Power Query with Dynamic Sample File

Pajeffery

New Member
Joined
Aug 7, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I have a Power Query where I need to reference two different Sample Files depending on a variable:

VBA Code:
let
    SourceType = Excel.CurrentWorkbook(){[Name="SourceType"]}[Content]{0}[Column1],
    SourceLocation = if SourceType = "Fileshare" then "C:\Fileshare" else "C:\Egnyte",
    Source = Folder.Files(SourceLocation),
    #"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
    #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File (3)", each #"Transform File (3)"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File (3)"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File (3)", Table.ColumnNames(#"Transform File (3)"(#"Sample File (3)")))
in
    #"Expanded Table Column1"

For the line:
Code:
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File (3)", each #"Transform File (3)"([Content])),

I'd like to replace "Transform File (3)" with a variable, this works for the first instance but not the second, for example:
Code:
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", VARIABLE, each #VARIABLE([Content])),

Can someone provide any guidance on what I should be using?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
The arguments aren't the same type. The first is just text (a column name) and the second is a function. It would be simpler to just use an if clause:

Power Query:
each if somevariable="x" then #"Transform File (3)"([Content]) else #"Transform File (4)"([Content])

for example.
 
Upvote 0

Forum statistics

Threads
1,223,871
Messages
6,175,099
Members
452,612
Latest member
MESTeacher

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