cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Regular Visitor

## Differnce Between two time Values , same Column

Hi All,

I am fairly new to power Bi and I want to get the Differnce between two times in the Same Column, as per the below image in excel. Can someone please help me with a formula for this.

1 ACCEPTED SOLUTION
Community Support

Hi @NellF ,

I have prepared two solutions to the problem:

• Use COLUMN to solve this problem

``````result_column =
VAR _1 =
CALCULATE (
MAX ( 'Table'[Time at Build Place] ),
FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
)
VAR _2 = 'Table'[Time at Build Place] - _1
RETURN
IF ( 'Table'[Index] = 1, BLANK (), _2 )
``````
• Use MEASURE to solve this problem

``````result_measure =
VAR _1 =
CALCULATE (
MAX ( 'Table'[Time at Build Place] ),
FILTER (
ALL ( 'Table' ),
'Table'[Index]
= SELECTEDVALUE ( 'Table'[Index] ) - 1
)
)
VAR _2 =
CALCULATE (
SUM ( 'Table'[Time at Build Place] ),
FILTER (
'Table',
'Table'[Time at Build Place] = SELECTEDVALUE ( 'Table'[Time at Build Place] )
)
) - _1
RETURN
IF ( SUM ( 'Table'[Index] ) = 1, BLANK (), _2 )
``````

Thank you for your questions and support! If it does not help, please provide more details with your desired out put and pbix file without privacy information.

Best Regards,

Yifan Wang

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

4 REPLIES 4
Community Support

Hi @NellF

1.        After moving a down one row, the two columns are subtracted. The first line outputs a blank value.

``````result =
VAR _1 =
CALCULATE (
MAX ( 'Table'[Time at Build Place] ),
FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
)
VAR _2 = 'Table'[Time at Build Place] - _1
RETURN
IF ( 'Table'[Index] = 1, BLANK (), _2 )
``````
1.         final output.

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

Best Regards,

Yifan Wang

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

Regular Visitor

But I am getting below error message, and I could not go ahead. Can you help me with this also. Many Thanks.

Community Support

Hi @NellF ,

I have prepared two solutions to the problem:

• Use COLUMN to solve this problem

``````result_column =
VAR _1 =
CALCULATE (
MAX ( 'Table'[Time at Build Place] ),
FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
)
VAR _2 = 'Table'[Time at Build Place] - _1
RETURN
IF ( 'Table'[Index] = 1, BLANK (), _2 )
``````
• Use MEASURE to solve this problem

``````result_measure =
VAR _1 =
CALCULATE (
MAX ( 'Table'[Time at Build Place] ),
FILTER (
ALL ( 'Table' ),
'Table'[Index]
= SELECTEDVALUE ( 'Table'[Index] ) - 1
)
)
VAR _2 =
CALCULATE (
SUM ( 'Table'[Time at Build Place] ),
FILTER (
'Table',
'Table'[Time at Build Place] = SELECTEDVALUE ( 'Table'[Time at Build Place] )
)
) - _1
RETURN
IF ( SUM ( 'Table'[Index] ) = 1, BLANK (), _2 )
``````

Thank you for your questions and support! If it does not help, please provide more details with your desired out put and pbix file without privacy information.

Best Regards,

Yifan Wang

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

Super User

you need column index or iD & use new window functions

Announcements

#### Fabric certifications survey

Certification feedback opportunity for the community.

#### Power BI Monthly Update - April 2024

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

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors