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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Gianluigi
Helper II
Helper II

calculate the number of hours between the rows

Hello,

Hello
How can I calculate the number of hours between the rows in the following table?

Example between the second line and the first should be about 48 hours.

Thank you 

 

Gianluigi_0-1708418398479.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Gianluigi ,

You can create a calculated column as below to get it, please find the details in the attachment.

Column = 
VAR _predatetime =
    CALCULATE (
        MAX ( 'Table'[dataEvento] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[dataEvento] < EARLIER ( 'Table'[dataEvento] )
        )
    )
RETURN
    DATEDIFF ( _predatetime, 'Table'[dataEvento], HOUR )

vyiruanmsft_0-1708502317276.png

In addition, you can also create a measure as below to get it.

Number of hours between the rows = 
VAR _datetime =
    SELECTEDVALUE ( 'Table'[dataEvento] )
VAR _predatetime =
    CALCULATE (
        MAX ( 'Table'[dataEvento] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[dataEvento] < _datetime )
    )
RETURN
    DATEDIFF ( _predatetime, _datetime, HOUR )

Best Regards

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @Gianluigi ,

You can create a calculated column as below to get it, please find the details in the attachment.

Column = 
VAR _predatetime =
    CALCULATE (
        MAX ( 'Table'[dataEvento] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[dataEvento] < EARLIER ( 'Table'[dataEvento] )
        )
    )
RETURN
    DATEDIFF ( _predatetime, 'Table'[dataEvento], HOUR )

vyiruanmsft_0-1708502317276.png

In addition, you can also create a measure as below to get it.

Number of hours between the rows = 
VAR _datetime =
    SELECTEDVALUE ( 'Table'[dataEvento] )
VAR _predatetime =
    CALCULATE (
        MAX ( 'Table'[dataEvento] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[dataEvento] < _datetime )
    )
RETURN
    DATEDIFF ( _predatetime, _datetime, HOUR )

Best Regards

And then this mistake too

Error Message:
The template does not include a table named Column in the eventi table

Hello
FYI, the new column doesn't work. Just save after a few minutes power bi reports this error

Error Message:
There is not enough memory to complete this operation. Please try again later when there may be more memory available.

Great!

 Thank you very much!

Jonvoge
Super User
Super User

Hi Gianluigi.

 

If you update to the latest version of Power BI, you can try out the brand new Visual Calculation feature to calculate row-by-row: Exploring Power BI Visual Calculations – Data – Marc (data-marc.com).

 

If you use the DATEDIFF() DAX function together with a Visual Calculation, you should be able to achieve what you want.
_____________________________________________________
I hope my comment was helpful.
If your question was answered, please mark your post as 'Solved' and consider giving me a 'Thumbs Up'.

Thank you !

Arul
Super User
Super User

@Gianluigi ,

In which visual, Do you want this?





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

Proud to be a Super User!


LinkedIn


In the table.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors