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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
SSIAB
New Member

How to calculate difference in previous row?

I have a date column that is sorted by week. I have another coulmn labeled PC valued with data values. How can I calculate to see the difference between each week in the PC column? Here is a screen shot below. 

SSIAB_0-1718656932906.png

 

1 ACCEPTED SOLUTION
Irwan
Solution Sage
Solution Sage

Hello @SSIAB 

 

please check if this will acommodate your need.

Irwan_2-1718668993558.pngIrwan_3-1718669029269.png

 

1. create calculated column for calculating week as you want to see weekly value difference

Week = WEEKNUM('Table'[Date],21) //put 21 for ISOWEEKNUM or depend on what you need

2. find previous week value then substract current week with previous week

Diff =
var _PreviousValue = MAXX(FILTER('Table','Table'[Week]<EARLIER('Table'[Week])),'Table'[Value]) //find previous week value
Return
'Table'[Value]-_PreviousValue
 
The first value return as 149 as there is no previous value, otherwise if you want to make it zero at the very first line then use this dax instead:
Diff =
var _PreviousValue = MAXX(FILTER('Table','Table'[Week]<EARLIER('Table'[Week])),'Table'[Value]) //find previous week value
Return
IF(
    'Table'[Week]=MIN('Table'[Week]),
    0,
    'Table'[Value]-_PreviousValue
)
Irwan_1-1718668954043.pngIrwan_5-1718669363926.png

 

 
Hope this will help you.
Thank you.

View solution in original post

1 REPLY 1
Irwan
Solution Sage
Solution Sage

Hello @SSIAB 

 

please check if this will acommodate your need.

Irwan_2-1718668993558.pngIrwan_3-1718669029269.png

 

1. create calculated column for calculating week as you want to see weekly value difference

Week = WEEKNUM('Table'[Date],21) //put 21 for ISOWEEKNUM or depend on what you need

2. find previous week value then substract current week with previous week

Diff =
var _PreviousValue = MAXX(FILTER('Table','Table'[Week]<EARLIER('Table'[Week])),'Table'[Value]) //find previous week value
Return
'Table'[Value]-_PreviousValue
 
The first value return as 149 as there is no previous value, otherwise if you want to make it zero at the very first line then use this dax instead:
Diff =
var _PreviousValue = MAXX(FILTER('Table','Table'[Week]<EARLIER('Table'[Week])),'Table'[Value]) //find previous week value
Return
IF(
    'Table'[Week]=MIN('Table'[Week]),
    0,
    'Table'[Value]-_PreviousValue
)
Irwan_1-1718668954043.pngIrwan_5-1718669363926.png

 

 
Hope this will help you.
Thank you.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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