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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
johnmay
Regular Visitor

Urgent! Measure Days diff same ID any status

Hello people!

Please, I need help to create a measure that is able to analyze the range of days from an "accept" status to the next in the same ID. However, there are 3 different scenarios:

 

10670 - If I have the status "proposal" I calculate the range of days from the status "accept" to it (in this case the interval is 10 days)

 

10671 - If I don't have the "proposal" I calculate from "accept" until the next status (in this case the next status is "done" and the interval will be 9 days)

 

10672 - If I don't have any status after "accept" I calculate the interval until today (14 days interval )

 

I need this measure for a tachometer view that will report the average of the days that in this case will be 10 + 9 + 14 / 3 IDs = 11 days

 

Work Item Id

STATE DATE

State

10670

23/04/2020

In Progress

10670

06/05/2020

Accept

10670

16/05/2020

Proposal

10671

23/04/2020

In Progress

10671

06/05/2020

Accept

10671

15/05/2020

Done

10672

23/04/2020

In Progress

10672

06/05/2020

Accept

 

2 ACCEPTED SOLUTIONS
v-deddai1-msft
Community Support
Community Support

Hi,

 

Would you please try to create a measure for calculating datediff for every situation:

 

Measure =

VAR A =

    CALCULATE (

        VALUES ( 'Table'[STATE DATE] ),

        FILTER (

            'Table',

            'Table'[Work Item Id] = MAX ( 'Table'[Work Item Id] )

                && 'Table'[State] = "proposal"

        )

    )

VAR B =

    CALCULATE (

        VALUES ( 'Table'[STATE DATE] ),

        FILTER (

            'Table',

            'Table'[Work Item Id] = MAX ( 'Table'[Work Item Id] )

                && 'Table'[State] = "Accept"

        )

    )

VAR C =

    CALCULATE (

        MAX ( 'Table'[STATE DATE] ),

        FILTER ( 'Table', 'Table'[Work Item Id] = MAX ( 'Table'[Work Item Id] ) )

    )

RETURN

    SWITCH (

        TRUE (),

        NOT ( A = BLANK () ), DATEDIFF ( B, A, DAY ),

        B = C, DATEDIFF ( B, TODAY (), DAY ),

        DATEDIFF ( B, C, DAY )

    )

 

Then create a measure to calculate their average:

 

Measure 2 = AVERAGEX(SUMMARIZE('Table','Table'[Work Item Id],"_datediff",[Measure]),[_datediff])

Untitled picture.png

For more details, please refer to the pbix file:  https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EdhMBMaKqgpPlfRD9I...

 

Best Regards,

Dedmon Dai

View solution in original post

Maybe:

 

Measure = 
    VAR __Table = 'Table'
    VAR __States = SELECTCOLUMNS(__Table,"State",[State])
    VAR __MaxDate = MAX('Table'[STATE DATE])
    VAR __MaxStatus = MAXX(FILTER('Table',[STATE DATE] = __MaxDate),[State])
RETURN
    SWITCH(TRUE(),
        "Proposal" IN __States,
                VAR __date1 = MAXX(FILTER(__Table,[State] = "Proposal"),[STATE DATE])
                VAR __date2 = MAXX(FILTER(__Table,[State] = "Accept"),[STATE DATE])
            RETURN
                (__date1 - __date2) * 1.,
        __MaxStatus = "Accept",(TODAY() - __MaxDate) * 1.,
            VAR __date1 = MAXX(FILTER(__Table,[State] = "Accept"),[STATE DATE])
            VAR __date2 = MINX(FILTER(__Table,[State] <> "Accept" && [STATE DATE] > __date1),[STATE DATE])
        RETURN
            (__date2 - __date1) * 1.
    )

 

PBIX is attached.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
johnmay
Regular Visitor

Hello people!

Please, I need help to create a measure that is able to analyze the range of days from an "accept" status to the next in the same ID. However, there are 3 different scenarios:

 

10670 - If I have the status "proposal" I calculate the range of days from the status "accept" to it (in this case the interval is 10 days)

 

10671 - If I don't have the "proposal" I calculate from "accept" until the next status (in this case the next status is "done" and the interval will be 9 days)

 

10672 - If I don't have any status after "accept" I calculate the interval until today (14 days interval )

 

I need this measure for a tachometer view that will report the average of the days that in this case will be 10 + 9 + 14 / 3 IDs = 11 days

 

Work Item Id

STATE DATE

State

10670

23/04/2020

In Progress

10670

06/05/2020

Accept

10670

16/05/2020

Proposal

10671

23/04/2020

In Progress

10671

06/05/2020

Accept

10671

15/05/2020

Done

10672

23/04/2020

In Progress

10672

06/05/2020

Accept

 

Dude, please don't cross post, this is just ridiculous now.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Maybe:

 

Measure = 
    VAR __Table = 'Table'
    VAR __States = SELECTCOLUMNS(__Table,"State",[State])
    VAR __MaxDate = MAX('Table'[STATE DATE])
    VAR __MaxStatus = MAXX(FILTER('Table',[STATE DATE] = __MaxDate),[State])
RETURN
    SWITCH(TRUE(),
        "Proposal" IN __States,
                VAR __date1 = MAXX(FILTER(__Table,[State] = "Proposal"),[STATE DATE])
                VAR __date2 = MAXX(FILTER(__Table,[State] = "Accept"),[STATE DATE])
            RETURN
                (__date1 - __date2) * 1.,
        __MaxStatus = "Accept",(TODAY() - __MaxDate) * 1.,
            VAR __date1 = MAXX(FILTER(__Table,[State] = "Accept"),[STATE DATE])
            VAR __date2 = MINX(FILTER(__Table,[State] <> "Accept" && [STATE DATE] > __date1),[STATE DATE])
        RETURN
            (__date2 - __date1) * 1.
    )

 

PBIX is attached.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
v-deddai1-msft
Community Support
Community Support

Hi,

 

Would you please try to create a measure for calculating datediff for every situation:

 

Measure =

VAR A =

    CALCULATE (

        VALUES ( 'Table'[STATE DATE] ),

        FILTER (

            'Table',

            'Table'[Work Item Id] = MAX ( 'Table'[Work Item Id] )

                && 'Table'[State] = "proposal"

        )

    )

VAR B =

    CALCULATE (

        VALUES ( 'Table'[STATE DATE] ),

        FILTER (

            'Table',

            'Table'[Work Item Id] = MAX ( 'Table'[Work Item Id] )

                && 'Table'[State] = "Accept"

        )

    )

VAR C =

    CALCULATE (

        MAX ( 'Table'[STATE DATE] ),

        FILTER ( 'Table', 'Table'[Work Item Id] = MAX ( 'Table'[Work Item Id] ) )

    )

RETURN

    SWITCH (

        TRUE (),

        NOT ( A = BLANK () ), DATEDIFF ( B, A, DAY ),

        B = C, DATEDIFF ( B, TODAY (), DAY ),

        DATEDIFF ( B, C, DAY )

    )

 

Then create a measure to calculate their average:

 

Measure 2 = AVERAGEX(SUMMARIZE('Table','Table'[Work Item Id],"_datediff",[Measure]),[_datediff])

Untitled picture.png

For more details, please refer to the pbix file:  https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EdhMBMaKqgpPlfRD9I...

 

Best Regards,

Dedmon Dai

Greg_Deckler
Community Champion
Community Champion

Seriously, another one?


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.