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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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