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
Anonymous
Not applicable

DATEDIFF on single column

I have a table that tracks the history of opportunities through different phases. I am trying to figure out how to create a measure that will tell me the difference in days (excluding weekends) that an opportunity spent in a phase:

 

Yuh.PNG

 

So for the above, I know this opportunity was in 'Discovery' from 9/26-10/9. Then in 'Presentation' from 10/9-11/14, etc. How can I calculate the difference in days for each StageName? Then, how can I get the average # of days for each StageName? The above is just one filtered opportunity but I would like to get an average number of days for each StageName across multiple opportunities.

 

I have somewhat gotten started but the solution I've found was centered around making it a measure which if I'm not mistaken you cannot average a measure:

2.PNG

1 ACCEPTED SOLUTION

Hi, @Anonymous 

It is unavailble to use DateDiff() function if you want to calculate workdays. You can try the following measure which excludes weekends.

 

Date Diff StageName = 
COUNTROWS (
        FILTER (
            CALENDAR (
                CALCULATE (
                    MIN ( 'Opportunity History'[CreateDate] ),
                    ALLEXCEPT ( 'Opportunity History', 'Opportunity History'[StageName] )
                ),
                CALCULATE (
                    MAX ( 'Opportunity History'[CreateDate] ),
                    ALLEXCEPT ( 'Opportunity History', 'Opportunity History'[StageName] )
                )
            ),
            NOT WEEKDAY ( [Date] ) IN { 1, 7 }
            
        )
    )

 

Result:

x.png

 

Best Regards

Allan

View solution in original post

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce the scenario.

c1.png

 

You can create a measure as follows.

AvgDayEachStage =

 DIVIDE(

    COUNTROWS(FILTER( CALENDAR( CALCULATE(

                        MIN('Opportunity History'[CreateDate]),

                        ALLEXCEPT('Opportunity History',

                                  'Opportunity History'[StageName])),CALCULATE(

                        MAX('Opportunity History'[CreateDate]),

                        ALLEXCEPT('Opportunity History',

                                  'Opportunity History'[StageName]))),

                                  not WEEKDAY([Date]) in {1,7}

                                  )

                                  )

                                  ,CALCULATE(COUNTROWS('Opportunity History'),ALLEXCEPT('Opportunity History','Opportunity History'[StageName])),0)

 

Result:

c2.png

 

If I misunderstand your thought, please show me your detailed sample data and expected result. I am glad to solve the problem for you.

 

Best Regards,

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

hi @v-alq-msft that was close but not quite what I needed. My apologies, I likely did not explain it well enough. So for each stage name, I need to know the difference between the earliest date and the latest date of the stagename:

 

1.PNG

So for Discovery: how many work days between 9/26 and 10/9

           Presentation: how many work days between 10/9 and 11/14

           Closing: how many work days between 11/14 and 11/21

 

I have formulas that return the earliest date and the latest date for each stagename and I've plugged those into a DateDiff calculation but it does not exclude work days. So for the above I have:

2.PNG

Which the Date Diff StageName formula is:

3.PNG

 

So it is calculating the days correctly but I need it to exclude weekends.

 

 

Hi, @Anonymous 

It is unavailble to use DateDiff() function if you want to calculate workdays. You can try the following measure which excludes weekends.

 

Date Diff StageName = 
COUNTROWS (
        FILTER (
            CALENDAR (
                CALCULATE (
                    MIN ( 'Opportunity History'[CreateDate] ),
                    ALLEXCEPT ( 'Opportunity History', 'Opportunity History'[StageName] )
                ),
                CALCULATE (
                    MAX ( 'Opportunity History'[CreateDate] ),
                    ALLEXCEPT ( 'Opportunity History', 'Opportunity History'[StageName] )
                )
            ),
            NOT WEEKDAY ( [Date] ) IN { 1, 7 }
            
        )
    )

 

Result:

x.png

 

Best Regards

Allan

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