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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Lihobday
Frequent Visitor

calculate number of working days between 2 dates and set 2 conditional formating

I am seeking help on powerbi! I had been figuring this out for weeks already!! Have 2 requirements... I have 2 dates. First is "assigned date" and second is "actual briefing date".

1. How may i calculate by working days the difference between actual brefing date and assigned date. Sometimes assigned date field is left blank and i will still need to calculate the difference of actual briefing date till today's date.

2. If the working days calculated is 10 days to 19 days old, can the work days be reflected as yellow. If more than 20 days, can the calculated work days be reflected at red?

Really need some experts advice here... thank you
2 ACCEPTED SOLUTIONS
v-shex-msft
Community Support
Community Support

Hi @Lihobday,

 

Smoupre's solution seems well, you can also take a look at below formula, I add the condtion to replace blank value to current date.

 

WorkDay Count =
COUNTROWS (
    FILTER (
        ADDCOLUMNS (
            CALENDAR (
                [Assigned date],
                IF ( [Actual briefing date] <> BLANK (), [Actual briefing date], TODAY () )
            ),
            "DayofWeek", WEEKDAY ( [Date], 1 )
        ),
        [DayofWeek] <> 1
            && [DayofWeek] <> 7
    )
)

Original table:

6.PNG

Result:

7.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

Hi @Lihobday,

 

If 'brief date' and 'actual close date' both not blank, which one you'd like to calculate?

 

In my opinion, I will choose the smaller one as the end date parameter:

WorkDay Count =
VAR closedate =
    MIN ( [Actual close date], [Actual briefing date] )
RETURN
    COUNTROWS (
        FILTER (
            ADDCOLUMNS (
                CALENDAR ( [Assigned date], IF ( closedate <> BLANK (), closedate, TODAY () ) ),
                "DayofWeek", WEEKDAY ( [Date], 1 )
            ),
            [DayofWeek] <> 1
                && [DayofWeek] <> 7
        )
    )

 

Notice: min and max function will ignore blank value.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

7 REPLIES 7
v-shex-msft
Community Support
Community Support

Hi @Lihobday,

 

Smoupre's solution seems well, you can also take a look at below formula, I add the condtion to replace blank value to current date.

 

WorkDay Count =
COUNTROWS (
    FILTER (
        ADDCOLUMNS (
            CALENDAR (
                [Assigned date],
                IF ( [Actual briefing date] <> BLANK (), [Actual briefing date], TODAY () )
            ),
            "DayofWeek", WEEKDAY ( [Date], 1 )
        ),
        [DayofWeek] <> 1
            && [DayofWeek] <> 7
    )
)

Original table:

6.PNG

Result:

7.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thank you for the solution XiaoXin Sheng! This work wonders!!! Had been figuring this out for a long time...!

Hi @Lihobday,

 

I'm glad to hear that my formula is helps for you.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi v-shex,

 

I have another problem that require some help. 

 

1. I have another column Close Date that has been added. How may i calculate by working days the difference between actual Close date and Brief date. The challenge is sometimes brief date field will be left blank. And i will get error from POWERBI "The start date or end date in Calendar Function can not be Blank value"

 

Is it possible to have a fomulae that calculates only if there is an entry in "Brief date" else it will not calculate? 

 

Thank you!!

 

Hi @Lihobday,

 

If 'brief date' and 'actual close date' both not blank, which one you'd like to calculate?

 

In my opinion, I will choose the smaller one as the end date parameter:

WorkDay Count =
VAR closedate =
    MIN ( [Actual close date], [Actual briefing date] )
RETURN
    COUNTROWS (
        FILTER (
            ADDCOLUMNS (
                CALENDAR ( [Assigned date], IF ( closedate <> BLANK (), closedate, TODAY () ) ),
                "DayofWeek", WEEKDAY ( [Date], 1 )
            ),
            [DayofWeek] <> 1
                && [DayofWeek] <> 7
        )
    )

 

Notice: min and max function will ignore blank value.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Greg_Deckler
Super User
Super User

Create a custom column in your data table:

 

Calc Date = IF(ISBLANK([AssignedDate]),TODAY(),[AssignedDate])

Use that to calculate working days. 

 

Use conditional formatting in a table visualization to show yellow and red values.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you Smoupre! 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.