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
samdep
Advocate II
Advocate II

Calculate Difference Between Rows (Row Data is a Measure, Not a Calc Column)

Hi Everyone,

 

I am looking to calculate the marginal product count to understand where we're seeing diminishing returns.

 

I have two columns of data - Days (which is a calculated DateDiff column I built in the table) and Product Count (which is a measure I created -- counting incidences of the sale of Product X).

 

I've seen a lot of solutions for calculating a running difference between current row and previous row where the row data is coming from calculated column in the table, but not where the row level data is a measure -- any help would be greatly appreciated!

 

 

Product Sales Data --

Day (Calc Column in Table)    Product Count (Measure)   Marginal Product Count

0                                             10 

1                                             12                                                  2

2                                             20                                                  8

 

And so on... 

 

Thank you! 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @samdep 

Please check the below picture and the link down below (sample pbix file) whether it is what you are looking for.

The measure is in the sample pbix file.

 

Picture2.png

 

Diff qty count =
VAR currentnumber =
MAX ( 'Table'[Day Calc Column] )
VAR onerowbefore =
CALCULATE (
MAX ( 'Table'[Day Calc Column] ),
FILTER ( ALL ( 'Table' ), 'Table'[Day Calc Column] < currentnumber )
)
VAR onerowbeforeqty =
CALCULATE ( [total qty], 'Table'[Day Calc Column] = onerowbefore )
RETURN
IF ( NOT ISBLANK ( onerowbeforeqty ), [total qty] - onerowbeforeqty, BLANK () )

 

 

https://www.dropbox.com/s/afahpn09tch8lii/samdep.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

2 REPLIES 2
samdep
Advocate II
Advocate II

Hi Jihwan,

 

This worked perfectly! Thank you so much for your help!! 

Jihwan_Kim
Super User
Super User

Hi, @samdep 

Please check the below picture and the link down below (sample pbix file) whether it is what you are looking for.

The measure is in the sample pbix file.

 

Picture2.png

 

Diff qty count =
VAR currentnumber =
MAX ( 'Table'[Day Calc Column] )
VAR onerowbefore =
CALCULATE (
MAX ( 'Table'[Day Calc Column] ),
FILTER ( ALL ( 'Table' ), 'Table'[Day Calc Column] < currentnumber )
)
VAR onerowbeforeqty =
CALCULATE ( [total qty], 'Table'[Day Calc Column] = onerowbefore )
RETURN
IF ( NOT ISBLANK ( onerowbeforeqty ), [total qty] - onerowbeforeqty, BLANK () )

 

 

https://www.dropbox.com/s/afahpn09tch8lii/samdep.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.