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
olimilo
Responsive Resident
Responsive Resident

NETWORKDAYS with Holidays from different countries

Hi guys, this is a bit of a challenge for me and I'm hoping someone can help lead me in the right direction.

 

I have a Records table that I need to check for the # of working days from StartDate to EndDate minus the number of holidays that occur within that time period based on the Country column of that same table. For example:

 

CountryCompleteByStartDateCompleteByEndDate
Korea, Republic of (South)11/16/201712/16/2017
Argentina5/9/20176/20/2017
Taiwan5/9/20176/20/2017
China6/30/20178/25/2017
USA7/1/20177/30/2017
Singapore2/16/20172/16/2017
China5/2/20176/30/2017
China5/12/20175/31/2017
China5/2/20176/30/2017
China4/27/20175/30/2017
China4/27/20175/31/2017
China5/16/20176/16/2017
Italy5/4/20176/3/2017

 

On that table, I have at least 7 countries. Now, I made a Holidays table:

 

DateCountry
1/1/2017China
1/2/2017China
1/27/2017China
1/28/2017Argentina
1/29/2017Argentina
1/30/2017Argentina
1/31/2017Brazil
6/17/2017Brazil
6/20/2017Brazil
7/9/2017Japan
8/21/2017Japan
10/9/2017Japan
11/27/2017South Korea
12/8/2017South Korea
12/25/2017South Korea

 

However, when I try to create a relationship between the Records table and the Holidays table, PBI won't let me because it requires a unique identifier for at least one table between the two (for this context, it should be the Holiday table). I've also been looking at several posts on the forums and it seems like it only deals with holidays from one country. I'm wondering if it is possible to do this on a multiple country basis in Power BI?

14 REPLIES 14
Clem_Fandango
Advocate II
Advocate II

For anyone finding this in the future, this post may help:
Calculate number of working days for each company - Microsoft Fabric Community

Clem_Fandango
Advocate II
Advocate II

6 years on and I'm struggling to find a solution to this too.  Even ChatGPT can't help. 😄

I'm wondering if the solution is multiple "Is Holiday" columns added to the DimDate table in.  eg 1 for each country. "Is Holiday - China", "Is Holiday - Australia", etc.

Quite how we'd go about creating those columns, I'm not sure.

I'm shouting into the void, hoping that someone will have a solution! Please? 🙂 

There is a really good API I use to get all Public Holidays, but it's quite restricted to calling one year and one country at the same time.

 

Info can be found here.

https://date.nager.at/Api

 

If your calling in Power BI, open up the Web connector and enter the URL like this 

 

I usually build a few years for one country in a dataflow and then append them into one Table 

JoeBarry_0-1692797702145.png

I then merge with my date table on the date column to have a column Holidays US for example. 

 

To solve the problem above. Make a One to Many relationship from the Date column in the Date Table to the completed by startdate in the table.

 

 

 

 

Holiday Days in Timeframe =

CALCULATE(
   COUNT('DIM Date'US_Holiday]),
     FILTER('DIM Date', 'DIM Date'[Date] >= Records[CompleteByStartDate] &&
         'DIM Date'[Date] < Records[CompleteByEndDate] && 'DIM Date'[US_Holiday] <> BLANK()))

 

 

 

 

Once you have this you can get the days between and then minus the amount of holidays

 

 

 

Days = DATEDIFF(Records[CompleteByStartDate], Records[CompleteByEndDate], DAY)- [Holidays Days in Timeframe]

 

 

 

 

Hope this helps 

Joe

If this post helps, then please Accept it as the solution 

Thanks Joe,

I'm OK with getting public holidays for 1 country via an API and then merging it with my Date Dimension table to create an "Is Holiday" type column.  

The issue I have is I'm now building a Date Dimension table in a Data Warehouse that will be used in multiple countries and not sure how that will work in practice.

Thinking out loud, I'm thinking we would have an "Is Holiday" column in the DimDate table for each country.  As long as reports are filtered to 1 country through RLS or explicitly we could have dynamic measures in the dataset file doing something like:

 

 

Holiday Days in Timeframe = 

var _country = SELECTEDVALUE('Dim Country') 
var _holiday_column = "'DIM Date'[Is Holiday " & _country & "]" 
//(Not sure the above is even possible in DAX) 

var _result = 

CALCULATE( 
DISTINCTCOUNTNOBLANK(_holiday_column), 
FILTER('DIM Date', 'DIM Date'[Date] >= Records[CompleteByStartDate] 
&& 'DIM Date'[Date] < Records[CompleteByEndDate])) 

return _result

 

 



I think it would be easier to just create a Public holiday table with Date, Country, CountryID, HolidayName columns. 

 

Adding a column to the date table can get messy, whereas, if you have one table, more countries can be added later without adding more columns.

 

The 2nd solution I created would then be useful. You can do RLS then on a DIM_Country table which has a one to many relationship with both the Holiday Table and the Records table

Thanks Joe. 
You're right,  using a DIM_Holiday_Country table (that will only ever have 1 country selected; either through a slicer or via RLS) that filters our Dim_Holidays (but not our Fact table) is our best shout I think.
That way, the user (or RLS) defines which country we're using for our Public Holidays in any measures related to working days.  We can then have Executive level report users still being able to view all countries in the report because we're not filtering the Fact Table.

I'm then going to create a calculated Is_Holiday column using DAX (LOOKUPVALUE) on my DimDate table to bring in just the filtered holidays in my DimHolidays table.

Funnily enough I came to the same conclusion as you after a long conversation with ChatGPT. 🙂 

Thanks for your help,
Clem

If you create a table just with all country holidays as above with a Country column (prefrablly a country id would be better) The below measure should work also

 

Holiday Days in Timeframe =

CALCULATE(
   COUNT(Holidays[Holiday]),
     FILTER('Holidays', 'Holidays'[Date] >= Records[CompleteByStartDate] &&
         'Holidays'[Date] < Records[CompleteByEndDate] && 'Holidays'[Country] = Records[Country))

 

Anonymous
Not applicable

Create a Date Table, that contains each day.  Join that Date table to your other 2 tables via their date columns.

olimilo
Responsive Resident
Responsive Resident

Hi @Anonymous, I think that's only possible if the dates do not repeat. If 3 countries celebrate a holiday on 1/1/2017:

 

DateCountry
1/1/2017USA
1/1/2017China
1/1/2017Taiwan
1/1/2017Japan
1/1/2017Brazil
1/2/2017Brazil
......
12/31/2017USA
12/31/2017Brazil
12/31/2017Japan

 

This will make me unable to use the table since both columns have repeating values. I am unable to use a Holiday Flag column too since I'm working with holiday listings of more than 1 country.

Anonymous
Not applicable

The date table will definately work because the Date Table is just every date possible.  There is only 1 occurance of any given date in this table.  Its something referred to as a Date Dimension Table.  The dates repeating in your existing tables is fine.

olimilo
Responsive Resident
Responsive Resident

I get what you're trying to say but how would you supply the countries that have a holiday? Let's say on 1/1/2017, 10 countries celebrate a holiday on that day. Would you be willing to provide a sample on how the data structure would look like?

Anonymous
Not applicable

Its really going to come down to how you write your measures.  For example you might have a measure that needs to count the number of holidays in your holiday table.  This measure might be part of a Matrix, thus there is already a date range and country filter.  Thus when the measure is run, it can only see "Dates" in your range and the country name.

 

On the other way around. If you were using a measure to "Count the number of countries on holiday", you might be doing this via a filter that uses a single date.  By doing this, the measure will only see that day and return the count.

Anonymous
Not applicable

Here is an alternate method if you just want to count the public holidays:

 

Create a custom column in your Project Table and use this:

PubHol Count = Calculate(
	count('PubHol'[Date]),
	'PubHol'[Country] = [Country],
	'PubHol'[Date] >= [CompleteByStartDate],
	'PubHol'[Date] <= [CompleteByEndDate]
)

You will need to up date the table name, i've guessed it.

 

olimilo
Responsive Resident
Responsive Resident

Okay, so this will be the first time I'll be working with a lot of dates, hope you bear with me here. Is this how the Date dimension table would look like?

 

2017-05-17 15_17_26-timeliness.xlsx - Excel.png

 

Now I'm wondering how I can incorporate the holidays on each country to another table that I can create a relationship with this table.

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.