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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
tims__
Frequent Visitor

Get sum of a column - filtered by groups/dimensions in other columns

Dear community,

I need some help with a calculation, where I want to find the sum of the "AMOUNT" column, but considering only my dimensions ID, SCENARIO and YEAR (and every combination of them) and not taking into account the different products in the corresponding column. So you have to read the table in a way that the amounts are only connected to an ID, in a specific scenario, in a specific year, but not to the products, that are only "doubling" the lines - as you can see from the amounts every two lines in this example.

Unfortunately, the scenarios, years and products can change, e.g. another ID may not have ProductA, another ID may not have a year 2023. So you can't filter by specific strings or values or just divide by 2. 🙂

 

This is the table:

 

IDSCENARIOYEARPRODUCTAMOUNT
1S12022ProductA70
1S12022ProductB70
1S12023ProductA80
1S12023ProductB80
1S22022ProductA60
1S22022ProductB60
1S22023ProductA65
1S22023ProductB65
2S12022ProductA50
2S12022ProductB50
2S12023ProductA30
2S12023ProductB30
2S22022ProductA60
2S22022ProductB60
2S22023ProductA20
2S22023ProductB20

 

I have been playing around a lot with FIRSTNONBLANK, ALLEXCEPT, FILTER, EARLIER and variables but did not find a proper solution. So I would be very glad if you could help me with this issue.

Thanks in advance

Tim

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@tims__ So, as a column, maybe:

Column = 
  VAR __ID = [ID]
  VAR __Scenario = [SCENARIO]
  VAR __Year = [YEAR]
  VAR __Table = FILTER(ALL('Table'),[ID] = __ID && [SCENARIO] = __Scenario && [YEAR] = __Year) 
RETURN
  SUMX(__Table,[AMOUNT])

If you want a measure, just wrap the first three VAR's with a MAX like VAR __ID = MAX('Table'[ID])



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Dear  @Greg_Deckler , thanks a lot for your reply and taking time to solve this!

Unfortunately, the code does not provide a solution, as the results in the column are the double of the (already) double, see table.

So for the first two rows I would only need (once) the Amount of 70. Also, if there would be a "Product C", I would still only need (the sum) 70 as a result for all rows that have this same combination of my dimensions (ID, Scenario, Year). So, for a new column in this example, a possible outcome would be: [70, blank, 80, blank, 60, blank ...]. Just a measure with the final result would also be fine.

Do you have a solution for this? Thanks in advance!

Tim

 

IDSCENARIOYEARPRODUCTAMOUNTVeh_Amount

1S12022ProductA70140
1S12022ProductB70140
1S12023ProductA80160
1S12023ProductB80160
1S22022ProductA60120
1S22022ProductB60120
1S22023ProductA65130
1S22023ProductB65130
2S12022ProductA50100
2S12022ProductB50100
2S12023ProductA3060
2S12023ProductB3060
2S22022ProductA60120
2S22022ProductB60120
2S22023ProductA2040
2S22023ProductB2040

 

@tims__ OK, how about this?

Measure = 
  VAR __Table = SUMMARIZE('Table',[ID],[SCENARIO],[YEAR],"__Value", AVERAGE([AMOUNT]))
RETURN
  SUMX(__Table,[__Value])

Greg_Deckler_0-1662663958086.png

 

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors