Dynamic Column Reference in Power Query

Guttural

New Member
Joined
Jan 21, 2015
Messages
9
I have a table which contains schedules for my employees, broken out into their start and end times. Like so:

EmployeeMonday_StartMonday_EndTuesday_StartTuesday_End
Bob09:30:0018:00:0009:30:0016:30:00
Alice08:00:0016:30:0008:00:00 16:30:00

<tbody>
</tbody>

And I have a list of dates which I join this table to, which ends up looking like this:

DateDoWEmployeeMonday_StartMonday_EndTuesday_StartTuesday_End
01/01/2017MondayBob09:30:0018:00:0009:30:0018:00:00
01/01/2017MondayAlice08:00:0016:30:0008:00:00 16:30:00
01/02/2017TuesdayBob09:30:0018:00:00 09:30:00 18:00:00
01/02/2017TuesdayAlice08:00:0016:30:00 08:00:00 16:30:00

<tbody>
</tbody>


After this, I want to create two new fields: Expected_Punch_In and Expected_Punch_Out, which are based on the Start and End times for a given day, and then I want to Remove the individual Monday/Tuesday/Wednesday/etc._Start/End columns. I'm currently doing this the long, ugly, kludgy way of having Power Query iterate through the long chain of if statements like so:

if [DoW] = "Monday" then [Monday_Start]
else if [DoW] = "Tuesday" then [Tuesday_Start]
etc.

but what I'd like to figure out how to do is to to make that process dynamic so that Power Query figures out which column to pull from based on the value in the DoW field..

Or, in other words, how do I replicate the Excel INDIRECT function in Power Query?
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,214,561
Messages
6,120,242
Members
448,951
Latest member
jennlynn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top