Created
July 15, 2022 16:48
-
-
Save sjtalkar/4175921b5d43251fb694c13bfe1994ea to your computer and use it in GitHub Desktop.
Remove null columns in Power Query M Language with iteration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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