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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

If statement in Power Query Advanced Editor.

Hi there, 

 

This is probably a relatively simple answer, but I have tried it a few ways with no success. 

I am wanting to build in a an if fuction to check if the file is local or web based before sourcing the info. 

This is what i have currently come up with, but i continue to get SyntaxError: Token Identifier expected.

 

Essentialy, I want the source to change between web and file depending on whether i am accessing the server or the localaly saved files. Ie. Source = Excel.Workbook(**Web/File**.Contents(FilePath & FileName), null, true)

 

let
FilePath = Excel.CurrentWorkbook(){[Name="FILEPATH"]}[Content]{0}[Column1],
FileName = Excel.CurrentWorkbook(){[Name="CTRM_FILE"]}[Content]{0}[Column1],
FileType = Excel.CurrentWorkbook(){[Name="FILETYPE"]}[Content]{0}[Column1],

if FileType="Web" then Source = Excel.Workbook(Web.Contents(FilePath & FileName), null, true) else if FileType="file" then Source = Excel.Workbook(File.Contents(FilePath & FileName), null, true)else null

EQUIPMENT_LIST_Table = Source{[Item="EQUIPMENT_LIST",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(EQUIPMENT_LIST_Table,{{"ID", type text}, {"DESCRIPTION", type text}, {"COMPANY_ID", type text}, {"Cost Type", type text}, {"RATE", Int64.Type}, {"CHARGE TYPE", type text}}),
#"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"ID", "DESCRIPTION", "COMPANY_ID", "Cost Type", "RATE", "CHARGE TYPE"})
in
#"Removed Other Columns"

 

Any help would be much appreciated 🙂

 

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @Anonymous 
please write it like so instead:
 Source = if FileType="Web" then Excel.Workbook(Web.Contents(FilePath & FileName), null, true) else if FileType="file" then Excel.Workbook(File.Contents(FilePath & FileName), null, true) else null

 

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

View solution in original post

2 REPLIES 2
ImkeF
Community Champion
Community Champion

Hi @Anonymous 
please write it like so instead:
 Source = if FileType="Web" then Excel.Workbook(Web.Contents(FilePath & FileName), null, true) else if FileType="file" then Excel.Workbook(File.Contents(FilePath & FileName), null, true) else null

 

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

Thanks Imke!

 

That did the trick 🙂

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.