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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Mani_ms
Helper I
Helper I

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.

Mani_ms_0-1597840723299.png

In the above example August also included in the total. but month fileterd untill July correctly.

 

Thanks,

Mani

 

1 ACCEPTED SOLUTION

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.

 

Ca1.jpg

 

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)

 

Ca2.jpg

 

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.

View solution in original post

7 REPLIES 7
v-zhenbw-msft
Community Support
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.

harshnathani
Community Champion
Community Champion

Hi @Mani_ms ,

 

You can remove VALUE from the formula.

 

https://dax.guide/value/

 

Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

 

Hi @harshnathani ,

 

Value i have used to convert text to number for the period. Somewhere i am missing..

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.

 

Ca1.jpg

 

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)

 

Ca2.jpg

 

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.

amitchandak
Super User
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

@amitchandak ,

Could you please help me out the YTD value prior period quantity based on current month.

Greg_Deckler
Super User
Super User

@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

 

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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