Skip to content

Instantly share code, notes, and snippets.

@bjulius
Last active July 24, 2025 05:52
Show Gist options
  • Save bjulius/e25412c0cd3e83857ff5c45052df5a83 to your computer and use it in GitHub Desktop.
Save bjulius/e25412c0cd3e83857ff5c45052df5a83 to your computer and use it in GitHub Desktop.
Dynamic M Function to Replace Blanks with Nulls ( #DataCleaning, #MCode, #M, #PowerQuery )
let
ReplaceBlanksWithNulls = (inputTable as table) as table =>
let
columnNames = Table.ColumnNames(inputTable),
replaceBlanksInColumn = (table, columnName) => Table.ReplaceValue(table, "", null, Replacer.ReplaceValue, {columnName}),
transformedTable = List.Accumulate(columnNames, inputTable, (state, current) => replaceBlanksInColumn(state, current))
in
transformedTable
in
ReplaceBlanksWithNulls
@darrellwolfe
Copy link

I had a weird issue where NULL was stored as a string in some data I received, this would be a good solution for that too. Thanks for sharing! Darrell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment