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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX measure to subtract current row value with next row

Hi All,

 

I am trying to create a measure and add it to a table visual to subtract current row value with the next row value. My table looks like below - 

I have slicers for ID, County & Org  and the table visual is filetered based on the selection and my LeadTime is the datediff between StartDate and EndDate and I am trying to calculate LeadRange which subtracts current row LeadTime with the Next row LeadTime

IDCaseCountyOrgStartDateEndDateLeadTimeLeadRangeLeadRange Formula
1ANCOrg14/1/20204/20/202019119-18
1BNCOrg14/2/20204/20/202018018-18
1BNCOrg14/2/20204/20/202018-118-19
2ASCOrg24/1/20204/20/202019119-18
2BSCOrg24/2/20204/20/202018118-17
2CSCOrg24/3/20204/20/202017  blank

 

I've tried multiple things and none worked. Any assistance is highly appreciated.

 

Regards,

Rohith

1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@Anonymous 

An index column is required, then you can create the measure:

 

Measure = SUM([LeadTime])-CALCULATE(SUM([LeadTime]),FILTER(ALLSELECTED('Table'),[Index]=MAX([Index])+1))

V-pazhen-msft_0-1620178052211.png


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
V-pazhen-msft
Community Support
Community Support

@Anonymous 

An index column is required, then you can create the measure:

 

Measure = SUM([LeadTime])-CALCULATE(SUM([LeadTime]),FILTER(ALLSELECTED('Table'),[Index]=MAX([Index])+1))

V-pazhen-msft_0-1620178052211.png


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

Portrek
Resolver III
Resolver III

Hi, rohithgndriv


You need to create a "column index" in power query, and after you put a new column in dax with the code below.

 

 

Difference =
var curIndex = TABLE[Index]
var curVal = TABLE[LeadTime]
var oldINDEX = TABLE[Index] + 1
var oldVal = CALCULATE(
FIRSTNONBLANK(TABLE[LeadTime],1),
FILTER(TABLE,
TABLE[Index]=oldINDEX))
return IF(CONTAINS(TABLE,TABLE[Index],oldINDEX), curVal-oldVal, 0)

 

 

Best regards.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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