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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Month over Month using a different static year ?

I am trying to write a cummlative sum for date range that looks like this

 

dateCummlative Sum 2020 Cummlative Sum 2015
2020 - June10050
2020 - July200100
2020 - August250150

 

Is it possible to write a cummalative sum of a year over another year in dax without using Date add and so i can just define the year as exactly 2019. The reason why i dont want to use Date add or any other (Date - 5 years), is because it is dynamic and it will not be correct next year.

 

Is this possible in dax?

 

What i have done so far:

I have managed this calculation which gives a total but does not break down correctly for month

 

var MinDate = DATE(2014,06,01)
var MaxDate = DATE(2015,05,31)
return CALCULATE(SUM(Sales[Amount]),FILTER(ALL ( Periods[Date] ), Periods[Date] <= MAX ( Periods[Date]) && Periods[Date] >= MinDate && [Date] <= MaxDate))
 

But it looks like this (doesnt give monthly breakdown).

 

dateCummlative Sum 2020 Cummlative Sum 2015
2020 - June100150
2020 - July200150
2020 - August250150
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

According to my understand , you wan to sum Amount based on each month of years dynamically ,right?


In my opinion, you could use Matrix and Slicer like this:

10.19.1.1.PNG

Or use the following formula:

dateSlicer =
VAR _maxDate =
    MAX ( 'Periods'[Date] )
VAR _minDate =
    MIN ( 'Periods'[Date] )
RETURN
    CALCULATE (
        SUM ( Sales[Amount] ),
        FILTER (
            ALL ( Periods ),
            'Periods'[Date] >= _minDate
                && 'Periods'[Date] <= _maxDate
                && 'Periods'[Date].[Month] = MAX ( 'Periods'[Date].[Month] )
        )
    )

10.19.1.2.PNG

 

Here is the pbix file.

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

According to my understand , you wan to sum Amount based on each month of years dynamically ,right?


In my opinion, you could use Matrix and Slicer like this:

10.19.1.1.PNG

Or use the following formula:

dateSlicer =
VAR _maxDate =
    MAX ( 'Periods'[Date] )
VAR _minDate =
    MIN ( 'Periods'[Date] )
RETURN
    CALCULATE (
        SUM ( Sales[Amount] ),
        FILTER (
            ALL ( Periods ),
            'Periods'[Date] >= _minDate
                && 'Periods'[Date] <= _maxDate
                && 'Periods'[Date].[Month] = MAX ( 'Periods'[Date].[Month] )
        )
    )

10.19.1.2.PNG

 

Here is the pbix file.

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

amitchandak
Super User
Super User

@Anonymous , Try like

 measure  =
 var MinDate = DATE(2014,06,01)
 var MaxDate = DATE(2015,05,31)
 return 
 calculate(SUM(Sales[Amount]), FILTER(All(Date), Date[DAte] <=Max(Date[date]) && Date[Date] >=MinDate && Date[Date] <= MaxDate))

 

I think datesytd should also work like

 

YTD Sales = CALCULATE(SUM(Sales[Sales]),DATESYTD('Date'[Date],"5/31"))
5 YTD back Sales = CALCULATE(SUM(Sales[Sales]),DATESYTD(dateadd('Date'[Date],-5,Year),"5/31"))

 

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 :radacad sqlbi My Video Series Appreciate your Kudos.

 

Please provide your feedback comments and advice for new videos
Tutorial Series Dax Vs SQL Direct Query PBI Tips
Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks for the response,

Is there anyway to avoid using a dynamic calculations like Date add?

YTD Sales: CALCULATE (SUM (Sales [Sales]), DATESYTD ('Date' [Date], "5/31"))
5 YTD Overdue Sales: CALCULATE (SUM (Sales [Sales]), DATESYTD (dateadd (' Date '[Date], - 5, Year), "5/31"))

Instead of using Dateadd use just the year 2019?

richbenmintz
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

 

Not really sure why you cannot use a filter on the Year and the Month, but I am not sure what your model looks like, assuming you have a Month column in your periods table you could try the formula below

 

var MinDate = DATE(2014,06,01)
var MaxDate = DATE(2015,05,31)
return CALCULATE(SUM(Sales[Amount]),
FILTER(ALL ( Periods[Date] ), (Periods[Date] <= MAX ( Periods[Date]) && Periods[Date] >= MinDate && [Date] <= MaxDate))&& Periods[Month] = MAX(Periods[Month]) )

 

Hope this Helps,
Richard
Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!



I hope this helps,
Richard

Did I answer your question? Mark my post as a solution! Kudos Appreciated!

Proud to be a Super User!


Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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