Home > Back-end >  add Multiple steps to a Power Query conditional statement
add Multiple steps to a Power Query conditional statement

Time:05-28

I have a single step conditional statement that works

    BlanksToNull = Table.ReplaceValue(#"Trimmed Text","",null,Replacer.ReplaceValue,Table.ColumnNames(#"Trimmed Text")),
    newMergedHeader = Excel.CurrentWorkbook(){[Name="newheader"]}[Content]{0}[Column1],
    #"Merged Columns" = 
     if newMergedHeader <> null then 
      Table.CombineColumns(BlanksToNull,mergeHeaders[List Of Headers For Concatenation], each Combiner.CombineTextByDelimiter("|", QuoteStyle.None)(List.RemoveNulls(_)),"Merged"),
    else 
        BlanksToNull

 in  
  if newMergedHeader <> null then     
     #"Merged Columns"
  else  
     BlanksToNull

But if newMergedHeader <> null I also want to add this #"Renamed Columns" = Table.RenameColumns(#"Merged Columns",{{"Merged",newMergedHeader}})

Is there a way to add this to the existing If statement? or do I need to write a second If statement?

I tried

#"Merged Columns" = 
     if newMergedHeader <> null then 
      Table.CombineColumns(BlanksToNull,mergeHeaders[List Of Headers For Concatenation], each Combiner.CombineTextByDelimiter("|", QuoteStyle.None)(List.RemoveNulls(_)),"Merged"),
      #"Renamed Columns" = Table.RenameColumns(#"Merged Columns",{{"Merged",newMergedHeader}})
    else 
        BlanksToNull

But this does not work

Thanks

CodePudding user response:

eyeballing, looks like you have an extra comma Merged"),

If you remove that and combine your statements I think you can do

#"Merged Columns" = 
 if newMergedHeader <> null then 
    Table.RenameColumns(
          Table.CombineColumns(BlanksToNull,mergeHeaders[List Of Headers For Concatenation], each Combiner.CombineTextByDelimiter("|", QuoteStyle.None)(List.RemoveNulls(_)),"Merged")
    ,{{"Merged",newMergedHeader}})
else BlanksToNull

but it is unclear to me why you need the whole tail end of things after the in instead of just replacing

in  
  if newMergedHeader <> null then     
    #"Merged Columns"
  else  
     BlanksToNull

with

in  #"Merged Columns"

since you already did all the work

  • Related