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

lead time and filters

I'm new to power bi. I' m trying to calculate the difference between two dates. Here is a example of my data.

id  operation   date    team
333 A   13/08/21    A
454 C   13/08/21    A
433 F   15/08/21    A
333 C   14/08/21    A
333 D   15/08/21    A
454 A   12/08/21    A
766 A   17/08/21    B
766 D   19/08/21    B
454 B   15/08/21    A
333 B   13/08/21    A

I want to calculate the average time between operation from all ids from one team. I need to be able to filter this by operations and team. example: average time between op A&C from team A. Any help will be very appreciated.

1 ACCEPTED SOLUTION

Hi  @pintoan ,

 

Based on my understanding,date for L is 04/08/2021,date for A is 03/08/2021,so the result should be 1.

If so,check below measure:

Measure =
VAR _opermax =
    CALCULATE ( MAX ( 'Table'[Operation] ), ALLSELECTED ( 'Table'[Operation] ) )
VAR _opermin =
    CALCULATE ( MIN ( 'Table'[Operation] ), ALLSELECTED ( 'Table'[Operation] ) )
VAR _team =
    SELECTEDVALUE ( 'Table'[TEAM] )
VAR _datemax =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[TEAM] = _team
                && 'Table'[Operation] = _opermax
        )
    )
VAR _datemin =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[TEAM] = _team
                && 'Table'[Operation] = _opermin
        )
    )
RETURN
    DATEDIFF ( _datemin, _datemax, DAY )

And you will see:

vkellymsft_0-1631084007711.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@pintoan , You can get a column, which can give you diff


time between Ops =
var _max = maxx(filter(Table, [Team] = earlier([team]) && [Date] < ealier([Date])), [Date])
return
datediff(_max,[date], day)

 

you can create measure based on this diff

 

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

I think i asked the wrong question. This is just a example. If i search for the difference between operation L and A the result is 2. But with the solution you gave i dont have this.

For example OP C- OP B should be 0 not 1

 

idOperationTEAMdate
500AA03/08/2021
500BA04/08/2021
500CA04/08/2021
500DA04/08/2021
500EA04/08/2021
500FA04/08/2021
500GA04/08/2021
500HA04/08/2021
500IA04/08/2021
500JA04/08/2021
500LA04/08/2021
500MA04/08/2021
500NA05/08/2021
500OA04/08/2021
500PA05/08/2021

Hi  @pintoan ,

 

Based on my understanding,date for L is 04/08/2021,date for A is 03/08/2021,so the result should be 1.

If so,check below measure:

Measure =
VAR _opermax =
    CALCULATE ( MAX ( 'Table'[Operation] ), ALLSELECTED ( 'Table'[Operation] ) )
VAR _opermin =
    CALCULATE ( MIN ( 'Table'[Operation] ), ALLSELECTED ( 'Table'[Operation] ) )
VAR _team =
    SELECTEDVALUE ( 'Table'[TEAM] )
VAR _datemax =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[TEAM] = _team
                && 'Table'[Operation] = _opermax
        )
    )
VAR _datemin =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[TEAM] = _team
                && 'Table'[Operation] = _opermin
        )
    )
RETURN
    DATEDIFF ( _datemin, _datemax, DAY )

And you will see:

vkellymsft_0-1631084007711.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

I have another question, this works fine when selecting 1 id, but i have multiple ID and want a average of time of them. Many thanks for this anyway, is a great upgrade for what i had.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors