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

Taking values from a column and make calculations on them as if they were stored in several columns

Hi,

 

I would like to calculate the date/time difference between rows that have the same [ASSET_ID_UNIT] and [C_ASSET_TRIP_ID].

From those lines I would like to take the [CC FLOW_DATE_TIME] where it is 110 - [CC FLOW_DATE_TIME] where it is 80

Like this:

Left is what I have. Right is what I would like to have:

2018_02_19_09_11_24_pool_test_Power_BI_Desktop.png

 

The model:

2018-02-19 09_17_42-pool test - Power BI Desktop.png

 

[ASSET_ID_UNIT] and [C_ASSET_TRIP_ID] come from table [FLOW_LINE_DETAIL]

[CC FLOW_DATE_TIME] and [FLOW_TYPE_ID] come from table [FLOW]

 

Does anyone have a clue how to do this?

 

I have been fiddling around with things like

GRAI 80 DATE := FIRSTNONBLANK(RELATEDTABLE(FLOW),FLOW[FLOW_TYPE_ID]=110)

I am not sure if related/relatedtable even works with a measure.

But nothing works...

 

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @Serge_van_Dun,

 

Could you try firstly changing the cross filter direction to Both for all the relationships in your model, then use the formulas below to see if it works in your scenario? Smiley Happy

 

both.PNG

GRAI 80 DATE :=
CALCULATE (
    FIRSTNONBLANK ( FLOW[CC FLOW_DATE_TIME], 1 ),
    FILTER ( FLOW, FLOW[FLOW_TYPE_ID] = 80 )
)
GRAI 110 DATE :=
CALCULATE (
    FIRSTNONBLANK ( FLOW[CC FLOW_DATE_TIME], 1 ),
    FILTER ( FLOW, FLOW[FLOW_TYPE_ID] = 110 )
)
Time Diff :=
IF (
    [GRAI 110 DATE] > [GRAI 80 DATE],
    DATEDIFF ( [GRAI 80 DATE], [GRAI 110 DATE], MINUTE )
)

 

Regards

View solution in original post

2 REPLIES 2
v-ljerr-msft
Employee
Employee

Hi @Serge_van_Dun,

 

Could you try firstly changing the cross filter direction to Both for all the relationships in your model, then use the formulas below to see if it works in your scenario? Smiley Happy

 

both.PNG

GRAI 80 DATE :=
CALCULATE (
    FIRSTNONBLANK ( FLOW[CC FLOW_DATE_TIME], 1 ),
    FILTER ( FLOW, FLOW[FLOW_TYPE_ID] = 80 )
)
GRAI 110 DATE :=
CALCULATE (
    FIRSTNONBLANK ( FLOW[CC FLOW_DATE_TIME], 1 ),
    FILTER ( FLOW, FLOW[FLOW_TYPE_ID] = 110 )
)
Time Diff :=
IF (
    [GRAI 110 DATE] > [GRAI 80 DATE],
    DATEDIFF ( [GRAI 80 DATE], [GRAI 110 DATE], MINUTE )
)

 

Regards

Hi v-ljerr-msft,

 

That is exactly what I needed!

Thanks a lot!

 

Kind regards,

Serge

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.