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

Add column showing number of workday for the month based on a date value

Hi guys,

 

I wanted to add a column to populate the number of work days based on an existing date column, do you know how I get this working?E.g. for 01/14/2016, the month is Jan/2016 and there are 23 work days.

image.png

 

Thanks in advance,

INC111

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @inc111,

 

First, you need a calendar table. In below example, I specifcy Monthday as the first day of each week.

dim date =
FILTER (
    ADDCOLUMNS (
        CALENDAR ( DATE ( 2016, 1, 1 ), DATE ( 2016, 12, 31 ) ),
        "WeekDay", WEEKDAY ( [Date], 2 )
    ),
    [WeekDay] <= 5
)

1.PNG

 

Then, add a calculated column in your fact table.

number of workday =
CALCULATE (
    COUNT ( 'dim date'[Date] ),
    FILTER (
        ALL ( 'dim date' ),
        'dim date'[Date].[Year] = YEAR ( EARLIER ( Table3[BillingDate] ) )
            && 'dim date'[Date].[MonthNo] = MONTH ( EARLIER ( Table3[BillingDate] ) )
    )
)

2.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yulgu-msft
Employee
Employee

Hi @inc111,

 

First, you need a calendar table. In below example, I specifcy Monthday as the first day of each week.

dim date =
FILTER (
    ADDCOLUMNS (
        CALENDAR ( DATE ( 2016, 1, 1 ), DATE ( 2016, 12, 31 ) ),
        "WeekDay", WEEKDAY ( [Date], 2 )
    ),
    [WeekDay] <= 5
)

1.PNG

 

Then, add a calculated column in your fact table.

number of workday =
CALCULATE (
    COUNT ( 'dim date'[Date] ),
    FILTER (
        ALL ( 'dim date' ),
        'dim date'[Date].[Year] = YEAR ( EARLIER ( Table3[BillingDate] ) )
            && 'dim date'[Date].[MonthNo] = MONTH ( EARLIER ( Table3[BillingDate] ) )
    )
)

2.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hey @v-yulgu-msft ,

Is it possible to get this to filter down to holidays? My compnay observes new years day so it would be 22 days in January. I'd also need to filter by all company holiday. Any help is appreciated. 

@v-yulgu-msft Thank you!

sokg
Solution Supplier
Solution Supplier

In Power Query editor

 

1. Convert billingdate to date type

2. Add column

 

Capture.JPG

 

then day --> name of date

3. Add column as 2 but day --> day of week

4. Add a conditional column like if day of week is 5 or 6 (depence of locale settings) then "weekend" else "working day".

 

Is that you want???

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.