I am using Power Query in Excel for Microsoft 365.
Please consider the following M Language code:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type of all to Text" = Table.TransformColumnTypes(Source,{{"A", type text}, {"B", type text}, {"C", type text}}),
#"Removed Unneeded Columns" = Table.RemoveColumns(#"Changed Type of all to Text",{"A"}),
...
in
#"Removed Duplicate Rows"
The problem I'm running into is that column A is not always present in the source table. If it is present, it must be removed. However, including it in the M Language code induces an error in instances when it is not present.
How may I change my M Language code to effectively handle both the case of column A being present and the case of column A not being present?
Remove Other Columns
.try...otherwise
; you could useTable.ColumnNames(#"Previous Step")
; remove ColumnA
from the list if it exists; then useTable.SelectColumns
referencing that list. And I'm sure there are other methods also.