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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
IlseV
Frequent Visitor

Create column with calculation of the difference of 2 cells which are in different columns and rows

Hi,

 

In excel this is very easy, but I would like to know if this is possible in power bi.

 

I have an overview of performances with begin- and endtime: 

example.png 

each row is 1 record with begin- and endtime: begin 13:48:37 and end 14:21:20

It is easy to calculate the difference per row, so the througputtime: e.g. first line: 14:21:20 minus 13:48:37 is 00:32:43

But what I can't solve is: to calculate the "lost time" till the next record:

I mean: the difference between the start time of record 2 and the end time of record 1:

14:23:20 minus 14:21:20 is 00:03:00 

And that calculation for every record till there is no more data.

 

I hope someone can help me.

Many thanks in advance

 

Ilse

 

 

 

 
 

 

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @IlseV ,

 

First create an index column;

Then create 2 columns as below:

Difference = 'Table'[End]-'Table'[Begin ]
lost time = 
var _nexbegin=CALCULATE(MAX('Table'[Begin ]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])+1))
Return
IF(_nexbegin=BLANK(),BLANK(),_nexbegin-'Table'[End])

And you will see:

Annotation 2020-09-14 105957.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

View solution in original post

4 REPLIES 4
v-kelly-msft
Community Support
Community Support

Hi @IlseV ,

 

First create an index column;

Then create 2 columns as below:

Difference = 'Table'[End]-'Table'[Begin ]
lost time = 
var _nexbegin=CALCULATE(MAX('Table'[Begin ]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])+1))
Return
IF(_nexbegin=BLANK(),BLANK(),_nexbegin-'Table'[End])

And you will see:

Annotation 2020-09-14 105957.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
amitchandak
Super User
Super User

@IlseV , Try a new column like

diff with last row = [begin tij in process] - maxx(filter(Table,[begin tij in process] < earlier([begin tij in process])),([End tij in process]))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi, thank you very much for your help!

I would never have found this.

One more question:

the first row can't calculate a difference because there is no row zero, so it returns the begin time 13:48:37

Is it possible to return this value (of the first row) blank?

Otherwise I get in trouble when I want to calculate sums or averages?

Many thanks,

Ilse

@IlseV - Try this:

diff with last row = 
  VAR __Current = [begin tij in process]
  VAR __Previous = MAXX(FILTER(Table,[begin tij in process] < EARLIER([begin tij in process])),[End tij in process])
RETURN
  IF(ISBLANK(__Previous) || YEAR(__Previous)<1900 || __Previous<0,BLANK(),[Current]-__Previous)

 



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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