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
NellF
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. 

NellF_0-1700803383601.png

 

1 ACCEPTED SOLUTION

Hi @NellF ,

Thanks for your reply, you can try to see if you are using measure instead of column. This might solve your problem.

  I have prepared two solutions to the problem:

  • Use COLUMN to solve this problem

vyifanwmsft_0-1701412170866.png

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

vyifanwmsft_1-1701412235235.png

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 )

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

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.

View solution in original post

4 REPLIES 4
v-yifanw-msft
Community Support
Community Support

Hi @NellF 

 

Please follow these steps:

  1.        index your table

vyifanwmsft_0-1700812989875.png

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

vyifanwmsft_1-1700813012041.png

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.

vyifanwmsft_2-1700813063651.png

How to Get Your Question Answered Quickly - Microsoft Fabric Community

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.

 

Hi All, Thank you for your prompt answers,

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

NellF_0-1700998457575.png

 

Hi @NellF ,

Thanks for your reply, you can try to see if you are using measure instead of column. This might solve your problem.

  I have prepared two solutions to the problem:

  • Use COLUMN to solve this problem

vyifanwmsft_0-1701412170866.png

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

vyifanwmsft_1-1701412235235.png

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 )

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

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.

Ahmedx
Super User
Super User

you need column index or iD & use new window functions

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.