Forum Discussion
Conditional merge columns in Query Editor
- Anonymous10 years ago
I don't think Table.TransformColumns is even the appropriate method for what you're trying to do. I would just add a new column that conditionally adds that prefix, then delete the old unneeded column.So instead of renaming slscode to SalesID#, add a new column called SalesID# then delete slscode.
... #"Renamed Columns3" = Table.RenameColumns(#"Changed Type",{{"acct", "Account#"}, {"OpenOrders$", "OpenOrder$"}}), #"AddedSalesID" = Table.AddColumn(#"Renamed Columns3", "SalesID#", each Text.Insert(Text.From([slscode]), 0, if [DIV] = "FC" then "FC0" else "BB0")), #"RemovedSLSCode" = Table.RemoveColumns(#"AddedSalesID", {slscode}) in #"RemovedSLSCode"
General syntax for if statement in M:
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [IsWeekend] then "TT" else "FF")
- sshweky10 years agoHelper III
Thank you! I think I did this right, but I am getting the following error:
SalesID# is type text. What is type list??
- Anonymous10 years agoNot applicable
Your syntax is incorrect for Table.TransformColumns. The second argument in Table.TransformColumns is expected to be a list. A list is essentially the same as an array. Not a single text value, but a series of separated values. See documentation here.
- sshweky10 years agoHelper III
I'm so sorry, but I can't understand the documentation. Here is my code ... can you show me how to structure?
= Table.TransformColumns(#"Renamed Columns3", "SalesID#", each if [DIV]="FC" then "FC0" else "BB0")