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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

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

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

View solution in original post

Anonymous
Not applicable

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

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

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

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

Anonymous
Not applicable

Hi @Lihobday,

 

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

 

Regards,

Xiaoxin Sheng

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

 

Anonymous
Not applicable

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

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.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thank you Smoupre! 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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