Forum Discussion
TheGreatYOLO
7 years agoFrequent Visitor
How to Get Max to work while grouping data
I have been struggling with a problem a couple times and wanted to know if there was a solution someone has for this problem. The issue is how do I get MAX to work when grouping data. Pro...
Ashish_Mathur
Super User
7 years agoTheGreatYOLO
7 years agoFrequent Visitor
Thanks for all the attempts.
Ashish, your new measure works only because there are two projects in the filter in asset 1. If you filter on Asset 2 you will notice it will take the top 2 values, where it needs to be dynamic according to the dataset (the top 1 of each unique project based on the filter).
Chuncz yours works except for the ones where there is no data in the current month. What I need it to do is look for the top 1 before the end of the month for each unique project. Basically Max prior to period chosen if there is no forecast uploaded in the current period.
What yours is doing
| Project 1 | Project 2 | Total | |
| Jul | 11 | 18 | 29 |
| Jun | 29 | missing | 29 |
| May | 12 | 13 | 25 |
Ashish =
SUMX (
CALCULATETABLE (
TOPN ( 2, Data, Data[Forecast Date], DESC ),
DATESBETWEEN (
'Calendar'[Date],
MINX ( ALL ( 'Calendar'[Date] ), 'Calendar'[Date] ),
MAX ( 'Calendar'[Date] )
)
),
[Total]
)
--------------------------------------------------------------------------------
Chuncz =
SUMX (
SUMMARIZE ( Data, Data[Project Number], Data[Asset Group] ),
CALCULATE (
SUMX ( TOPN ( 1, Data, Data[Forecast Date], DESC ), Data[Amount] )
)
)