0

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

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that work great!. My first Power Query if statement attempt that's why the tail end things were there. I will study your post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.