Forum Discussion
Calculate total not matching with Max function
Hi ,
I have table by country and quantity with month category.
I am bringing YTD quantity based on Max Function if current month equal to Max and i want to return until previous month YTD quantity.
By month i can able to get the desired result but in total its giving including the current month.
In the above example August also included in the total. but month fileterd untill July correctly.
Thanks,
Mani
Hi Mani_ms ,
Do you want to calculate the cumulative value when the month is equal to today's month, the other months show the value of the current month?
For example, when the month name is Aug, it will calculate the cumulative value.
If yes, you can use the following measure.
Measure = var _YTD = CALCULATE(SUM('Table'[quantity]),FILTER(ALLEXCEPT('Table','Table'[Country]),'Table'[Month number]<=MAX('Table'[Month number]))) var _currentmonth = FORMAT(TODAY(),"mmm") var _sum = SUM('Table'[quantity]) return IF( MAX('Table'[Month name])=_currentmonth,_YTD,_sum)If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BTW, pbix as attached.
7 Replies
- Greg_Deckler
Community Champion
Mani_ms - This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376
Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907 - amitchandak
Super User
Mani_ms , Not very clear. You can use time intelligence, if you date with date calendar.
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31")) Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31")) This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31")) Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))Power BI — YTD
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a- Mani_ms
Helper I
Could you please help me out the YTD value prior period quantity based on current month.
- AnonymousNot applicable
Hi Mani_ms ,
You can remove VALUE from the formula.
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)- Mani_ms
Helper I
Hi Anonymous ,
Value i have used to convert text to number for the period. Somewhere i am missing..
- v-zhenbw-msft
Community Support
Hi Mani_ms ,
Do you want to calculate the cumulative value when the month is equal to today's month, the other months show the value of the current month?
For example, when the month name is Aug, it will calculate the cumulative value.
If yes, you can use the following measure.
Measure = var _YTD = CALCULATE(SUM('Table'[quantity]),FILTER(ALLEXCEPT('Table','Table'[Country]),'Table'[Month number]<=MAX('Table'[Month number]))) var _currentmonth = FORMAT(TODAY(),"mmm") var _sum = SUM('Table'[quantity]) return IF( MAX('Table'[Month name])=_currentmonth,_YTD,_sum)If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BTW, pbix as attached.
- v-zhenbw-msft
Community Support
Hi Mani_ms ,
How about the result after you follow the suggestions mentioned in my original post?
Could you please provide more details or expected result about it If it doesn't meet your requirement?
If you've fixed the issue on your own please kindly share your solution. If the above posts help, please kindly mark it as a solution to help others find it more quickly.
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.