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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Calculating SUM of dynamic amount of rows from second table

What I have is data like this:

CategoryForecast on Cycle TimeOrderTitle
Category A

2

1

XYZ

Category A

2

2

XYZ

Category B

3

3

XYZ

Category A

5

4

XYZ

Category C

1

5

XYZ

Category A

5

6

XYZ

Category C

10

7

XYZ

Category B

10

8

XYZ

 

Now, what my data is trying to do is to try and forecast the delivery (based on the forecast) when certain items will be complete AND when certain category of things are complete - to help inform decision making about prioritizing the work (changing the order).

 

What I'm trying to achieve here is this - I want to be able to pick a category (let's say Category A) and calculate the forecasted delivery based on the forecast but it NEEDS to take into account every other item from different category that is prioritized somewhere "in the middle". To do that - instead of a simple SUM function for each Forecast for Category A - I need to do something different here, which includes:

  • identifying the order position which includes the furthest Category A item on the ordered list (in this case - Order #6)
  • calculate SUM of the forecast for every item on the list (regardless of the Category) from first to the MAX identified in previous step - so basically do a SUM of X rows in that unfiltered table, where the X is defined by the maximum

How can I achieve that?

 

I've tried bunch of stuff - I've already managed to get my max (by a simple calculation of MAX of that column) but so far I was unable to use that dynamic MAX to limit the number of rows taken into calculation - anything I did either resulted in (a) filtered table which summarized only the items that belonged to Category A or (b) didn't care about the maximum and calculated the SUM for the whole table. I don't seem to get a right way to use dynamic/filtered MAX and apply it to unfiltered results somehow.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

However! I've found the issue.

It shouldn't be, as You've suggested:


 

 

 

 

Measure =
  VAR __Category = MAX('Table'[Category])
  VAR __Max = MAXX(FILTER(ALL('Table'),[Category] = __Category),[Forecast on Cycle Time])
RETURN
  SUMX(FILTER(ALL('Table'),[Forecast on Cycle Time] <= __Max),[Forecast on Cycle Time])

 

 

 

 


But rather:

 

 

 

 

  VAR __Category = MAX('Test'[Category])
  VAR __Max = MAXX(FILTER(ALL('Test'),[Category]= __Category),[Order])
RETURN
  SUMX(FILTER(ALL('Test'),[Order] <= __Max),[Forecast])

 

 

 

 

 

In the VAR __Max we are looking for the maximum ORDER not the maximume value of forecast 🙂

And that suits the criteria and provide correct results.

 

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@Anonymous I believe you want:

Measure =
  VAR __Category = MAX('Table'[Category])
  VAR __Max = MAXX(FILTER(ALL('Table'),[Category] = __Category),[Forecast on Cycle Time])
RETURN
  SUMX(FILTER(ALL('Table'),[Forecast on Cycle Time] <= __Max),[Forecast on Cycle Time])


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...
Anonymous
Not applicable

However! I've found the issue.

It shouldn't be, as You've suggested:


 

 

 

 

Measure =
  VAR __Category = MAX('Table'[Category])
  VAR __Max = MAXX(FILTER(ALL('Table'),[Category] = __Category),[Forecast on Cycle Time])
RETURN
  SUMX(FILTER(ALL('Table'),[Forecast on Cycle Time] <= __Max),[Forecast on Cycle Time])

 

 

 

 


But rather:

 

 

 

 

  VAR __Category = MAX('Test'[Category])
  VAR __Max = MAXX(FILTER(ALL('Test'),[Category]= __Category),[Order])
RETURN
  SUMX(FILTER(ALL('Test'),[Order] <= __Max),[Forecast])

 

 

 

 

 

In the VAR __Max we are looking for the maximum ORDER not the maximume value of forecast 🙂

And that suits the criteria and provide correct results.

 

Anonymous
Not applicable

I think You're onto something here. I hoped it will work but it seems to provide invalid data for some reason.Or maybe I have made some simple mistake. I wanted to upload the files to show You what's wrong but it doesn't let me for some reason. Anyway, below are the screenshots:

1. When none of the category is chosen:

Choroszewicz_J_0-1643636719020.png

2. When I pick one of the category to filter:

Choroszewicz_J_1-1643636757738.png

 

And here are the values that I've measured in Excel to help me verify if these measures are working correctly:

CategoryTitleStory PointsOrder   MAXSUM of ALL (based on MAX) 
Feat 1XYZ21  Feat 1525 
Feat 2XYZ52  Feat 2947 
Feat 3XYZ33  Feat 31057 
Feat 1XYZ104  Feat 4934 
Feat 1XYZ55      
Feat 2XYZ16      
Feat 3XYZ37      
Feat 4XYZ58      
Feat 2XYZ139      
Feat 3XYZ1010      
          
 SUM:57       

 

So for Feat 4 that I've picked up on the screenshot, the value should be 34 and it is 24.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.