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
apatwal
Helper III
Helper III

Difference between cumulative values

Hi,

 

I need help in creating DAX.

I have an requirement to work on Incremental Margin which is cumulative of Margin and want to plot difference of incremental margin.

I need that Incremental Margin for 2022 should subtract the 2021 Incremental Margin from the comparable week. E.g., For week of Jan 3, 2022, we need to calculate the week’s total incremental margin and then subtract the incremental margin from week of Jan 4, 2021.

 

below is the DAX which is used to create measure to calculate cumulative of Incremental Margin

Incremental Margin Cumulative =
CALCULATE(
    SUM('table'[Incremental Margin]),
    FILTER(
        CALCULATETABLE(
            SUMMARIZE(
                'table',
                'table'[YrMnthCode],
                'table'[YearMonth]
            ),
            ALLSELECTED('table')
        ),
        ISONORAFTER(
            'table'[YrMnthCode], MAX('table'[YrMnthCode]), DESC,
            'table'[YearMonth], MAX('table'[YearMonth]), DESC
        )
    )
)
 
Let me know how can I build DAX for this.
3 REPLIES 3
amitchandak
Super User
Super User

@apatwal , You need have column like these in you date tbale, along with year and week

 

new columns
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

 

Then you can have week measures like

This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))
 

Last year Week= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -52)))

or

Last year Week= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -53)))

 

or

 

This week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year]) && 'Date'[Week] = Max('Date'[Week]) ))
Last year same week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year])-1 && 'Date'[Week] = Max('Date'[Week])))

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

Hi @amitchandak 

 

Thanks for your reply!

Just to inform we don't have separate date table, date column is included in our dataset and we have millions of records in our dataset.

 

@apatwal ,  Try like

example

week Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Sales'[Date],-364,DAY))

 

or

This week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Table'),'Table'[Year]=max('Table'[Year]) && 'Table'[Week] = Max('Table'[Week]) ))
Last year same week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Table'),'Table'[Year]=max('Table'[Year])-1 && 'Table'[Week] = Max('Table'[Week])))

 

 

But My advice would be to get a date table added to the model. Things would be easy

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

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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