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

How to add # of days in a date excluding weekends per country

Hi, I am looking for answers but can't find it. I need to add # of days to a date. However, per country there are specific numbers. Example:
Australia - 31 days
India - 10 days, so on. These two countries should exclude weekend when adding date, for other countries no need to exclude. Thank you in advance!

1 ACCEPTED SOLUTION

Hi @Anonymous ,

According to your description, here's my solution.

1. Create a new table.

vkalyjmsft_0-1646113690824.png

Date =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2022, 1, 1 ), DATE ( 2022, 12, 31 ) ),
    "Week", WEEKDAY ( [Date], 2 )
)

2.Create a new measure.

Expected date =
VAR _T =
    FILTER (
        ALL ( 'Date' ),
        'Date'[Date]
            > MAXX (
                FILTER ( 'Table', 'Table'[Country] = MAX ( 'Table'[Country] ) ),
                'Table'[Date]
            )
            && 'Date'[Week] <> 6
            && 'Date'[Week] <> 7
    )
VAR _T2 =
    ADDCOLUMNS ( _T, "Rank", RANKX ( _T, [Date],, ASC, DENSE ) )
RETURN
    SWITCH (
        MAX ( 'Table'[Country] ),
        "Australia", MAXX ( FILTER ( _T2, [Rank] = 31 ), [Date] ),
        "India", MAXX ( FILTER ( _T2, [Rank] = 10 ), [Date] ),
        MAX ( 'Table'[Date] ) + 2
    )

Get the expected result.

vkalyjmsft_1-1646113806667.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

9 REPLIES 9
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

Sorry I'm not very clear about your desired output.

Do you want to count the days from beginning of the year exclude weekends, like this?

vkalyjmsft_0-1645779106911.png

Then what did you mean "Australia - 31 days, India - 10 days", for these two countries, can you show the expected result in Excel like me?

 

Best Regards,
Community Support Team _ kalyj

 

Anonymous
Not applicable

Hi, please see this example. I have a country column and query receieved dat. Per country they have an allowable due date, it will depend on their allowable due date.

katerinepr_0-1645784057923.png

 

 

Hi @Anonymous ,

According to your description, here's my solution.

Create a measure.

Expected date =
VAR _Day =
    SWITCH ( MAX ( 'Table'[Country] ), "Australia", 31, "India", 10, 2 )
RETURN
    MAX ( 'Table'[Date] ) + _Day

 Get the correct result.

vkalyjmsft_0-1645784322751.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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! So far, I'm getting the result. However, I need to exclude weekends on calculation for Australia and India.

Hi @Anonymous ,

do you mean for Australia, when the date 1/1/2022 +31, the 31 days should exclude weekends?

Best Regards,
Community Support Team _ kalyj

Anonymous
Not applicable

Yes, weekends should be included. There are other countries that can include weekends when counting.

Hi @Anonymous ,

According to your description, here's my solution.

1. Create a new table.

vkalyjmsft_0-1646113690824.png

Date =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2022, 1, 1 ), DATE ( 2022, 12, 31 ) ),
    "Week", WEEKDAY ( [Date], 2 )
)

2.Create a new measure.

Expected date =
VAR _T =
    FILTER (
        ALL ( 'Date' ),
        'Date'[Date]
            > MAXX (
                FILTER ( 'Table', 'Table'[Country] = MAX ( 'Table'[Country] ) ),
                'Table'[Date]
            )
            && 'Date'[Week] <> 6
            && 'Date'[Week] <> 7
    )
VAR _T2 =
    ADDCOLUMNS ( _T, "Rank", RANKX ( _T, [Date],, ASC, DENSE ) )
RETURN
    SWITCH (
        MAX ( 'Table'[Country] ),
        "Australia", MAXX ( FILTER ( _T2, [Rank] = 31 ), [Date] ),
        "India", MAXX ( FILTER ( _T2, [Rank] = 10 ), [Date] ),
        MAX ( 'Table'[Date] ) + 2
    )

Get the expected result.

vkalyjmsft_1-1646113806667.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

Anonymous
Not applicable

Hello!!! THanks for this solution! It saved me! Appreciate it a lot.

mh2587
Super User
Super User

# of Days = CALCULATE(COUNT('Calendar'[Date]),FILTER('Calendar',[Date]>=MAX('Table'[StartDate])&&[Date]<=MAX('Table'[EndDate])&&[Weekday]<>6&&[Weekday]<>7))

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



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.