Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
roberts_stats
New Member

Sum a column with duplicates

How many apples are there at each Farm (with DAX)

 

FarmBarrelApples  Taster   Vote
North Farm     Green Barrel     150JohnSweet   
North FarmGreen Barrel150SueSweet
North FarmRed Barrel150JohnBitter
South FarmBlue Barrel200JohnSweet
South FarmBlue Barrel200SueSweet
South FarmPink Barrel300JohnSweet
South FarmPink Barrel300SueBitter
South FarmPink Barrel300CarolSweet
South FarmRed Barrel50CarolBitter

 

We want to create a measure which would sum the quantity of any Farm or any Barrel?

Like the Apple Measure shown below for example ...

ciderFarms.jpg

 

 

Farm,Barrel,Apples,Taster,Vote
North Farm,Green Barrel,150,John,Sweet
North Farm,Green Barrel,150,Sue,Sweet
North Farm,Red Barrel,150,John,Bitter
South Farm,Blue Barrel,200,John,Sweet
South Farm,Blue Barrel,200,Sue,Sweet
South Farm,Pink Barrel,300,John, Sweet
South Farm,Pink Barrel,300,Sue,Bitter
South Farm,Pink Barrel,300,Carol,Sweet
South Farm,Red Barrel,50,Carol,Bitter

1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @roberts_stats 

You can consider add a summarized table to remove the duplicates records and keep the valid record columns.

Calculated Table:

Table 2 = SUMMARIZE('Table','Table'[Farm],'Table'[Barrel],'Table'[Apples])

Then you can perform calculations based on this summary table.

From the summary table you can easily tell how many apples are there at each Farm.

veasonfmsft_0-1666259433130.png

Best Regards,
Community Support Team _ Eason

View solution in original post

3 REPLIES 3
v-easonf-msft
Community Support
Community Support

Hi, @roberts_stats 

You can consider add a summarized table to remove the duplicates records and keep the valid record columns.

Calculated Table:

Table 2 = SUMMARIZE('Table','Table'[Farm],'Table'[Barrel],'Table'[Apples])

Then you can perform calculations based on this summary table.

From the summary table you can easily tell how many apples are there at each Farm.

veasonfmsft_0-1666259433130.png

Best Regards,
Community Support Team _ Eason

ValtteriN
Super User
Super User

Hi,

I am going to give a few pointers which should help you to solve this issue:

You can use CALCULATE to modify filter context of a measure/function by using functions such as ALL, REMOVEFILTERS, ALLEXCEPT.  E.g. ALL(Table[column]) will remove filters affecting that column.


The use case you are describing is common and I recommend checking these resources to understand more:

Introducing CALCULATE in DAX - SQLBI
CALCULATE function (DAX) - DAX | Microsoft Learn
Filter context in DAX - SQLBI

I believe you can create your measure after reading these.


I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @ValtteriN 

 

Thanks your answer, I'm going to edit and clarify my question a little because I don't believe those links resolve this question necessarily.

We want to create a measure which would sum the quantity of any Farm or any Barrel, not just filtering the sum to find one Barrel or one Farm.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.