Forum Discussion

JollyRoger01's avatar
JollyRoger01
Icon for Helper III rankHelper III
5 years ago
Solved

How to select and delete columns that have all zeros or all blanks

I have the following table that I would like to delete columns from if those columns contain all zeros or all blanks. To try and learn M language, I'd like to try and find out how to select the colum...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi JollyRoger01 

     

    Me again. You want it?

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZBLCsAgDETvkrWL3kdcVK2Cn/tvS3Aa0hKh4IOBeZEQ7+kgR+cGCm4JcYMIbCeD1w/ZQATjPRV7F4gq69kCksrSs1xBVlkEthvQ8cdy7HVcoCD3z+zA4hV56J7lic0b8jp+uAE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"20201218" = _t, #"20201221" = _t, #"20201222" = _t, #"20201223" = _t, #"20210104" = _t, #"20210105" = _t, #"20210106" = _t]),
        Custom1 = Table.ColumnNames(  Source),
        #"Converted to Table" = Table.FromList(Custom1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
        #"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each [a=Table.Column(Source, [Column1]),
    b=List.MatchesAll( a, each _ ="0") or List.MatchesAll( a, each _ ="")][b]),
        #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = false)),
        Custom2 = Table.SelectColumns(Source,  #"Filtered Rows"[Column1])
    in
        Custom2