Forum Discussion
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:
| Country | CompleteByStartDate | CompleteByEndDate |
| Korea, Republic of (South) | 11/16/2017 | 12/16/2017 |
| Argentina | 5/9/2017 | 6/20/2017 |
| Taiwan | 5/9/2017 | 6/20/2017 |
| China | 6/30/2017 | 8/25/2017 |
| USA | 7/1/2017 | 7/30/2017 |
| Singapore | 2/16/2017 | 2/16/2017 |
| China | 5/2/2017 | 6/30/2017 |
| China | 5/12/2017 | 5/31/2017 |
| China | 5/2/2017 | 6/30/2017 |
| China | 4/27/2017 | 5/30/2017 |
| China | 4/27/2017 | 5/31/2017 |
| China | 5/16/2017 | 6/16/2017 |
| Italy | 5/4/2017 | 6/3/2017 |
On that table, I have at least 7 countries. Now, I made a Holidays table:
| Date | Country |
| 1/1/2017 | China |
| 1/2/2017 | China |
| 1/27/2017 | China |
| 1/28/2017 | Argentina |
| 1/29/2017 | Argentina |
| 1/30/2017 | Argentina |
| 1/31/2017 | Brazil |
| 6/17/2017 | Brazil |
| 6/20/2017 | Brazil |
| 7/9/2017 | Japan |
| 8/21/2017 | Japan |
| 10/9/2017 | Japan |
| 11/27/2017 | South Korea |
| 12/8/2017 | South Korea |
| 12/25/2017 | South 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?
15 Replies
- AnonymousNot applicable
Create a Date Table, that contains each day. Join that Date table to your other 2 tables via their date columns.
- olimiloPost Prodigy
Hi Anonymous, I think that's only possible if the dates do not repeat. If 3 countries celebrate a holiday on 1/1/2017:
Date Country 1/1/2017 USA 1/1/2017 China 1/1/2017 Taiwan 1/1/2017 Japan 1/1/2017 Brazil 1/2/2017 Brazil ... ... 12/31/2017 USA 12/31/2017 Brazil 12/31/2017 Japan 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.
- AnonymousNot 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.
- AnonymousNot applicable
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? 🙂- JoeBarrySolution Sage
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.
If your calling in Power BI, open up the Web connector and enter the URL like this
https://date.nager.at/api/v3/publicholidays/2023/US Filter out non day off daysI usually build a few years for one country in a dataflow and then append them into one Table
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
- JoeBarrySolution Sage
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))
- AnonymousNot applicable
For anyone finding this in the future, this post may help:
Calculate number of working days for each company - Microsoft Fabric Community - PawelPNew Member
olimilo wrote: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:
Country CompleteByStartDate CompleteByEndDate Korea, Republic of (South) 11/16/2017 12/16/2017 Argentina 5/9/2017 6/20/2017 Taiwan 5/9/2017 6/20/2017 China 6/30/2017 8/25/2017 USA 7/1/2017 7/30/2017 Singapore 2/16/2017 2/16/2017 China 5/2/2017 6/30/2017 China 5/12/2017 5/31/2017 China 5/2/2017 6/30/2017 China 4/27/2017 5/30/2017 China 4/27/2017 5/31/2017 China 5/16/2017 6/16/2017 Italy 5/4/2017 6/3/2017 On that table, I have at least 7 countries. Now, I made a Holidays table:
Date Country 1/1/2017 China 1/2/2017 China 1/27/2017 China 1/28/2017 Argentina 1/29/2017 Argentina 1/30/2017 Argentina 1/31/2017 Brazil 6/17/2017 Brazil 6/20/2017 Brazil 7/9/2017 Japan 8/21/2017 Japan 10/9/2017 Japan 11/27/2017 South Korea 12/8/2017 South Korea 12/25/2017 South 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?
I had the same issue. My tables look almost the same and this worked for me:
Working Days = NETWORKDAYS( Table1[CompleteByStartDate],Table1[CompleteByEndDate],1, CALCULATETABLE( VALUES(Table2[Date]),Table2[Country]=EARLIER(Table1[Country])))​