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
ellevy12
Frequent Visitor

Calculating difference between consecutive rows

hello

 

i am new to power bi , and i have some struggle with this. 

 

my data look like this (small portion:)

DATE / sum

2018-07-01 / 200

2017-09-03 / 400

2016-19-04 / 500

 

i want to calculate the difference between those dates , so i want to create new column:

 

DATE / sum / new column

2018-07-01 / 200    /    400

2017-09-03 / 400   /    500

2016-19-04 / 500 /   

 

only problems on the data sets: 

1. dates are not strictly consecutive , meaning i can have 5 dates in 2018 and 10 dates in 2017 

2. i want those calculation to be filtred by the user. meaning - if user deselect the '2017-09-03' date , then calculation will changed to the following:

 

DATE / sum / new column

2018-07-01 / 200    /    500

2016-19-04 / 500 /   

 

 

thanks.

1 ACCEPTED SOLUTION

Hi all,

 

i manged to solve this using this answer:

 

Answer

 

basicly i had to calculate for each date the previous date (under the current filters) and then return the result for that date

 

View solution in original post

7 REPLIES 7
v-jiascu-msft
Employee
Employee

Hi @ellevy12,

 

Please provide a sample of the original data. Since the dates aren't in order by dates, how can we determine which one is former, which one is latter?

 

 

Best Regards,
Dale

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

Hi all,

 

i manged to solve this using this answer:

 

Answer

 

basicly i had to calculate for each date the previous date (under the current filters) and then return the result for that date

 

Thanks for sharing, @ellevy12.

 

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

Up until that last requirement, you could have just used a calculated column with EARLIER.

 

Now, you will need a measure and use a VAR to grab your current table (as filtered by user). Then, use ADDCOLUMNS to add a column using EARLIER to that table and do your calculations.

 

Here is an article on the use of EARLIER:

See my article on Mean Time Before Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

sorry i think i mix things up.. actualy what i reffered to as my data is actualy a visual matrix / table  based on the data.

 

does this change somthing ?

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
LivioLanzo
Solution Sage
Solution Sage

You cannot do this by using a Calculated Column but you can do it using a Measure. Is a measure ok?   Also can you include in the dataset you have provided any column that is relevant for the calculation

 

 

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

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.