Forum Discussion
Add column if not exists
- 6 years ago
hi Anonymous
You may refer to this post:
Regards,
Lin
Look at Table.ColumnCount
https://docs.microsoft.com/en-us/powerquery-m/table-columncount
or Table.ColumnNames
https://docs.microsoft.com/en-us/powerquery-m/table-columnnames
to see if the column is present or not. Based on that you can then modify your subsequent Table.SelectColumns call.
Anonymous how you are appending files together? You can check the missing column name in the file and then add it conditionally something like this.
=if List.Count(List.FindText(Table.ColumnNames( <<your previous step>> ), "ColumnName" ))= 1 then <<previous step>> else Table.AddColumn(<<previous step>>, "ColumnName", each "", type text)
it basically checks if a column name already exists, if yes do nothing otherwise add new column.
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.⚡
- Anonymous6 years agoNot applicable
Hi parry2k ,
Sorry, I'm still in the training phase of Power Editor.
Is that code you would write in a custom column or in Advanced Editor?- v-lili6-msft6 years agoCommunity Support
hi Anonymous
You may refer to this post:
Regards,
Lin