Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

DAX Help

I need help creating a DAX measure for the following task in the below dataset

YearMonthSales
2019Jan100
2019Feb110
2019Mar120
2019Apr130
2019May140
2019Jun150
2019Jul160
2019Aug170
2019Sep180
2019Oct190
2019Nov200
2019Dec210
2020Jan220
2020Feb230
2020Mar240
2020Apr250
2020May260

 

I need May 2020 sales as March 2020 + April 2020, April 2020 sales as March 2020. March 2020 sales needs to March 2019 to Feb 2020 (Sum of sales)

4 Replies

  • Anonymous , id every month logic is changing if need rolling you can do that with date table

    2/3

     

    Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-3,MONTH))
    Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX(Sales[Sales Date]),-3,MONTH))
    Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-3,MONTH))

     

    Rolling 3 till last 1 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],Startofmonth(dateadd(Sales[Sales Date],-1,month)),3,MONTH))

     

    To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
    https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
    https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
    https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

    See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


    Appreciate your Kudos.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Amit, I am using the same logic to create 6 months rolling sums. But for YTD I am failing, I am wondering is there a way to create the same maybe as a calculated column? 

      • v-easonf-msft's avatar
        v-easonf-msft
        Community Support

        Hi, Anonymous 

        Could you please tell me whether your problem has been solved?
        If yes, you could accept the helpful answer as solution. You also could share your own solution here. For now, there is no content of description in the thread. If you still need help, please share more details to us.

         

        Best Regards,
        Community Support Team _ Eason

  • FrankAT's avatar
    FrankAT
    Community Champion

    Hi Anonymous 

    take a look at the following solution:

     

     

    Sum of Sales = SUM('Table'[Sales])
    
    
    Running Total = 
    CALCULATE(
        [Sum of Sales],
        FILTER(
            ALLEXCEPT('Table','Table'[Year]),
            'Table'[Date] <= MAX('Table'[Date])
        )
    )

     

    With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
    FrankAT (Proud to be a Datanaut)