Forum Discussion
when passing the value returned from MAX function, the DAX returns incorrect output
I have a measure which calculates the current year: Current Year = YEAR(TODAY()). This returns 2020 and I can visualize it in a Card visual.
Another measure to calculate max year in my data: Max Forecast Year = MAX(PopForecastTest[year]). This returns 2041 and this too can be visualized correctly in a Card visual.
Now, I create another measure as:
Vickram , Should have worked. Try this change and check
Max Forecast Year = MAXX(allselected(PopForecastTest),PopForecastTest[year])
4 Replies
- amitchandak
Super User
Vickram , Should have worked. Try this change and check
Max Forecast Year = MAXX(allselected(PopForecastTest),PopForecastTest[year])
- Vickram
Helper III
Hi Amit, this works amazingly. What is the difference between MAX that I used and the MAXX you suggested?
Also, passing the value from measure to a variable then used that in the Filter in the above DAX as suggested by Fowmy also works.
Thanks to you both for the prompt reply.
- Fowmy
Super User
Check the following modified measure:
Max Forecast year population = VAR _MaxYear = [Max Forecast Year] return CALCULATE( SUM('PopForecastTest'[ForecastPop]), FILTER(ALL(PopForecastTest[year]), PopForecastTest[year] = _MaxYear ) )Simpler version:
Max Forecast year population =
VAR _MaxYear = [Max Forecast Year] returnCALCULATE(
SUM('PopForecastTest'[ForecastPop]),
PopForecastTest[year] = _MaxYear
)________________________
If my answer was helpful, please click Accept it as the solution to help other members find it useful
Click on the Thumbs-Up icon if you like this reply 🙂