Forum Discussion

Mani_ms's avatar
Mani_ms
Icon for Helper I rankHelper I
6 years ago
Solved

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

  • 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's avatar
      Mani_ms
      Icon for Helper I rankHelper I

      amitchandak ,

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

  • Anonymous's avatar
    Anonymous
    Not applicable

    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)

     

     

    • Mani_ms's avatar
      Mani_ms
      Icon for Helper I rankHelper I

      Hi Anonymous ,

       

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

      • v-zhenbw-msft's avatar
        v-zhenbw-msft
        Icon for Community Support rankCommunity 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's avatar
    v-zhenbw-msft
    Icon for Community Support rankCommunity 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.