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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Referencing external tables column in function

Hi all,


Hope you can help me with this.

My basic question is, how can I reference an external table from within a function from within the PowerQuery editor.


Here's my setup:

I have a table with tasks, and one with Holidays.
For my monitoring, I am using a function that will deduct the holidays from the actual task duration.

 

Table "TASK"

Task IDStartEnd
aaa0012020-01-052020-01-06
aaa0022020-01-122020-02-01
aaa0032020-04-012020-04-15
aaa0042020-04-092020-04-20

 

Table "HOLIDAY"

Holiday nameDate
New years Eve2020-01-01
Good Friday2020-04-10
Easter Sunday2020-04-12
Easter Monday2020-04-13
Labour Day2020-05-01

 

Now, to get the info from the "Holidays" table into my function, so far I have:

  • Joined the Holiday table with my Tasks table (all [HOLIDAYS.Date] to each of [Task ID])
  • Ran my function, referencing the newly created [HOLIDAYS.Date] column in the [TASKS] table

 

 

// working days are from Mon=0 to Fri=4 and not in holiday list
fnIsWorkingDay = (dt as date) as logical => 
     Date.DayOfWeek(dt, Day.Monday) < 5 and not List.MatchesAny(HolidayList, each _ = dt)​

 

 

  • Removed the column

As the [TASKS] table is huge (with >60k entries), the join is taking quite some time, and is very inefficient.

 

Is there a way, to directly reference the [HOLIDAYS.Date] column as a list, instead of joining and using what's called "HolidayList" in the function above?

That would probably take out most of the processing time for me...

 

Edit: marked that I am working in the PowerQuery editor, not in PowerBI directly. If the question needs to be moved, please do so. Sorry for the inconvenience!

7 REPLIES 7
ImkeF
Community Champion
Community Champion

Hi @Anonymous ,

there are a couple of things here that don't align:

 

1) How can you join a date with a number? ("Joined the Holiday table with my Tasks table (all [HOLIDAYS.Date] to each of [Task ID])")

2) What is that "HolidayList" that you're refering in the function? There is no mention/description of it so far:

 

// working days are from Mon=0 to Fri=4 and not in holiday list
fnIsWorkingDay = (dt as date) as logical =>
Date.DayOfWeek(dt, Day.Monday) < 5 and not List.MatchesAny(HolidayList, each _ = dt)​

 

In case you're looking for a NETWORKDAYS function that handles holidays as well, please check out my blogpost here: https://www.thebiccountant.com/2020/02/20/date-networkdays-function-for-power-query-and-power-bi/  

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hello @ImkeF,
Sorry I was not clear earlier.

What I am doing is joining all entries from the table "HOLIDAYS" to each entry from the table "TASKS". Result of this process is a list that is located in a separate column, called "HolidayList", that I am then checking against Start- and end date.

The code for this step in Power Query is:

=Table.AddColumn(#"LastStep", "Holidays", each HOLIDAYS[Date])

Afterwards, I am passing this table to the function that I described earlier calculating the elapsed time as parameter "HolidayList".

ImkeF
Community Champion
Community Champion

Hi @Anonymous ,

are you able to share a sample workbook with some mockup data please?

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

amitchandak
Super User
Super User

Create a date table and merge your holidays in that. And refer to working day formula in the given file between two dates and use that

https://www.dropbox.com/s/y47ah38sr157l7t/Order_delivery_date_diff.pbix?dl=0

 

In this file check how date has been to Order dim. Same way you can move holiday to date table and create 1,0 for working and  non working days

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hello @amitchandak - Would you have additional insight into this topic, or would you advise me to raise this topic somewhere else?

@ImkeF@Ashish_Mathur  can you help on this

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks.
I should have said this before I think, but I'm working in the PowerQuery editor here...
I'll update the question in a sec.

I guess this advice won't work there?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors