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
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
Super User
Super User

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
Super User
Super User

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
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.