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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Calculating time between two dates in Visual Matrix

Dear MS PBI Experts I am hoping someone can help me out here... I think this problem is relatively simply but I only started using PBI today... I have tidied up my data and presented it as a Matrix, where each row represents a flight and each column is take-off and land. In Excel I can subtract one number by the other to get the duration of the journey... but how do I do this on PBI Matrix Visulisation... any idea? Thank you all!

 

PBI Help.JPG

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

Hi  @Anonymous ,

 

Create a measure as below:

_Duration(Minutes)= 
VAR _group=CALCULATETABLE(VALUES('Table'[DateTime]),FILTER(ALL('Table'),'Table'[flight_id]=MAX('Table'[flight_id])))
var _takeoff=MINX(_group,'Table'[DateTime])
var _lande=MAXX(_group,'Table'[DateTime])
Return
DATEDIFF(_takeoff,_lande,MINUTE)

And you will see:

Annotation 2020-08-24 142400.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

5 REPLIES 5
v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

Create a measure as below:

_Duration(Minutes)= 
VAR _group=CALCULATETABLE(VALUES('Table'[DateTime]),FILTER(ALL('Table'),'Table'[flight_id]=MAX('Table'[flight_id])))
var _takeoff=MINX(_group,'Table'[DateTime])
var _lande=MAXX(_group,'Table'[DateTime])
Return
DATEDIFF(_takeoff,_lande,MINUTE)

And you will see:

Annotation 2020-08-24 142400.png

For the related .pbix file,pls see attached.

 

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

HI @Anonymous 

I would use the below measure

Duration = 
Var seconds = DATEDIFF([landed],[takeoff],SECOND)
Var Hours   = INT([seconds]/3600)
Var Minutes = INT(MOD([seconds],3600)/60)
Var Seconds = MOD(MOD([seconds],3600),60)
Var HH = IF(LEN([Hours])=1,CONCATENATE("0",[Hours]),CONCATENATE("",[Hours]))
Var MM = IF(LEN([Minutes])=1,CONCATENATE("0",[Minutes]),CONCATENATE("",[Minutes]))
Var SS = IF(LEN([Seconds])=1,CONCATENATE("0",[Seconds]),CONCATENATE("",[Seconds]))
 
RETURN CONCATENATE([HH],CONCATENATE(":",CONCATENATE([MM],CONCATENATE(":",[SS]))))

 

camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

You can create a measure like this:

Capture.PNG



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

Proud to be a Super User!



Anonymous
Not applicable

Thank you so much for your help everyone! ... but I struggled to get it to work.

 

A little background on the raw data, every single flight_id corresponds to two seperate row: one for take off and one for landing - see snapshot below:

 

(Stamp field just combine date and time field.)

 

raw data.JPG

So first I pulled the data into a Matrix visulisation to get it in the format below so I can see the correspnoding landing and take off time for each fligth_id. But now I'm strugglign to find the duration as the SUMX function doesn't recognise takeoff and landing as a variable in the tabe...

 

PBI Help.JPG

 

Thank you everyone once again for your help!

Hi @Anonymous ,

 

See the attached file, I've created 2 examples. 

First with your data model and other using pivot table.

 

 



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

Proud to be a Super User!



Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.