Forum Discussion

Einomi's avatar
Einomi
Helper V
2 years ago
Solved

Delete Blank Columns in Nested Tables

Hi, I have quickly searched on the forum but did not find what I need, I want to combine multiple PDF, but I prefer to write my own M code than using the UI, which is sometime limited and maybe my M...
  • AlienSx's avatar
    AlienSx
    2 years ago

    Einomi my bad - wrong name after "in". I'll correct that soon. You may create blank query and place the following code in there (half of job is done by dufoq3 - check his query as well, it's also works)

    (tbl) => 
        [ReplaceBlankToNull = Table.TransformColumns(tbl, {}, each if _ = "" then null else _),
        profile = Table.Buffer(Table.Profile(ReplaceBlankToNull)),
        columns_to_delete = Table.SelectRows(profile, each [Count] = [NullCount])[Column],
        delete_columns = Table.RemoveColumns(ReplaceBlankToNull, columns_to_delete)][delete_columns]

    name the query as you wish. E.g. "fxRemoveBlankColumns". This is now a custom function that removes all null/blank columns from the table. In your "main" column make the following statement: 

    remove_blanks = Table.TransformColumns(ref_to_last_step, {"Content",  fxRemoveBlankColumns})

    Let us know if it worked.