Run a Query Conditionally

Hi

I want to run a query only if a parameter value = “Update” then it performs the Query if not the query ends.

I thought of doing this using a on a If then else … but I think I have something wrong- any ideas how to fix it or how to do it a better way?

IfThen.xlsx (19.0 KB)

Thanks

Allister

If

Hi @AllisterB ,

Else condition missing in your logic. I have added null for your example purpose and you can change as per your requirement.

Let me know if its help ?

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Salary", Int64.Type}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Name", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Name.1", "Name.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Name.1", type text}, {"Name.2", type text}}),

result = 
if param1 = "Update" 
then #"Changed Type1" **else null**

in
    #"result"

Thank you for that - I have updated theCode but now I get an error. If theparam1 i<> “Update” I don’t want the table to change and I don’t want an error. is there an error Handling piece of code i need to use ?
IfThen.xlsx (19.1 KB)

Check if this helps ?

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Salary", Int64.Type}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Name", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Name.1", "Name.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Name.1", type text}, {"Name.2", type text}}),

result = 
if param1 = "Update" 
then #"Changed Type1" else Source

in
    #"result"

Hi
Thank You again. However I did not explain my self eth best.

The Query loads to a table in teh workbook. if the para1 <> Update then I want the table that the Query loads to to remain unchanged. If the para1 = Update then the Query needs to Load to the table.

Having the else Source means that the Source Table to will load to the tableTable unaffected by teh Query code
I think I just need a way to avid eth error… or perhaps there’s another way.
:slight_smile:

ok in that case for error handling use Try … otherwise function.

Hi

where would I use try otherwise in theQuery ?

Please refer sample file for your reference. Please modify as per your requirement.

IfThen (1).xlsx (19.2 KB)

1 Like

Thank You Rajender - works well - thank You for your patience too