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! Learn more

Reply
harshagraj
Post Partisan
Post Partisan

Datediff for alternate rows

Hello All,

 

How do it get date diff in sec. It should be group by ModelNr and Station Nr. 
Eg: Datediff(17-11-2020 14:46:02,17-11-2020 14:46:11,Sec)

 

Snip.png

4 REPLIES 4
harshagraj
Post Partisan
Post Partisan

Hello @Anonymous  thanks a lot helping. But unfortunately i cant do column because its live connection. And i tried the measur but i am getting wrong values. Please see the attached.snip6.JPG

Anonymous
Not applicable

Hi @harshagraj ,

According to the official document, it may caused by some limitations...

I did it in three ways after grouping ModelNr and Station Nr columns, please try

ModelNrStation =
[ModelNr ] & [Station Nr]
Measure = 
DATEDIFF (
    CALCULATE (
        MAX ( 'Table'[DepositCarrier_C] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[ModelNrStation] = MAX ( 'Table'[ModelNrStation] )
                && 'Table'[DepositCarrier_C] < MAX ( 'Table'[DepositCarrier_C] )
        )
    ),
    MAX ( 'Table'[PreStopperArrival_C] ),
    SECOND
)
ColumnMethod1 = 
DATEDIFF (
    [DepositCarrier_C],
    MINX (
        FILTER (
            'Table',
            [ModelNr ] = EARLIER ( [ModelNr ] )
                && [Station Nr] = EARLIER ( [Station Nr] )
                && [PreStopperArrival_C] > EARLIER ( [PreStopperArrival_C] )
        ),
        [PreStopperArrival_C]
    ),
    SECOND
)
ColumnMethod2 = 
DATEDIFF (
    CALCULATE (
        MAX ( 'Table'[DepositCarrier_C] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[ModelNrStation] ),
            [DepositCarrier_C] < EARLIER ( 'Table'[DepositCarrier_C] )
        )
    ),
    [PreStopperArrival_C],
    SECOND
)

My final output looks like this:

11.20.2.1.PNG

Here is the pbix file.

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

amitchandak
Super User
Super User

@harshagraj , Try a column like

 

datediff(minx(filter(table, [ModelNr] =earlier([ModelNr]) && [Station Nr] =earlier([Station Nr]) && [prestoparrivalC] > earlier([prestoparrivalC])),[prestoparrivalC]),[prestoparrivalC] , second)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello thankyou so much for the reply. I tried inserting a Measure and I am on Direct Query mode. I am getting below error. I am not getting a column after Earlier. Am i missing something? Please help snip1.JPG

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