Skip to content

Instantly share code, notes, and snippets.

@sjtalkar
Created July 15, 2022 16:48
Show Gist options
  • Save sjtalkar/4175921b5d43251fb694c13bfe1994ea to your computer and use it in GitHub Desktop.
Save sjtalkar/4175921b5d43251fb694c13bfe1994ea to your computer and use it in GitHub Desktop.
Remove null columns in Power Query M Language with iteration
get_curr_cols = Table.ColumnNames (set_section_headers),
get_null_cols = List.Generate(
() => [counter = 0, x = get_curr_cols, result="False"] ,
each [counter] < List.Count([x]),
each [counter=[counter]+1 ,
x= get_curr_cols,
result= if List.NonNullCount(Table.Column(set_section_headers, [x]{counter})) <= 0 then "True" else "False"
],
each [result] ),
null_pos = List.PositionOf(get_null_cols, "True", Occurrence.All),
null_col_names = List.Transform (null_pos, each get_curr_cols{_}),
clean_table = Table.RemoveColumns (set_section_headers, null_col_names),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment