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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

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
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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