• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Getting wrong List Count after removing Null Values

MBS

Member
Hi All,
I have to search valid header row in table. For this I have to check first 10 rows of table.
I am finding total no of filled columns without nulls.
Table.ToColumns(Table.FirstN([Data],10)) //created a list. "Data" is a column name with "Tables" as objects in rows.
and l got list of, say 15, having last list have null values

So to remove that null list I used
List.RemoveNulls(Table.ToColumns(Table.FirstN([Data],10)))

Then I count the List by
List.Count(List.RemoveNulls(Table.ToColumns(Table.FirstN([Data],10))))

but i am getting the result as 15 only whereas 14 is expected. Can you please elaborate why it is happening.

Thanks,
 
The null values are one level down the list. You are counting the sublists.
For another forum question I suggested this approach.
Code:
    Table_as_cols = List.Transform(List_of_tables, each Table.ToColumns(_) ),
    Remove_empty_lists = List.Transform(Table_as_cols, each List.Select(_, each not List.IsEmpty(List.RemoveNulls(_)) )),
    Table_from_cols = List.Transform(Remove_empty_lists, each Table.FromColumns(_)),
    Table_to_rows = List.Transform(Table_from_cols, each Table.ToRows(_)),
    Pos_of_headrs_and_select_range = List.Transform(Table_to_rows, each
            [
                Values =  List.Transform(_, each List.Distinct(List.RemoveNulls(_)) ),
                Count = List.Transform(Values, each List.Count(_)),
                Max = List.Max(Count),
                Pos = List.PositionOf(Count, Max),
                Tbl = Table.FromRows(List.Skip(_, Pos)),
                No_null_rows = Table.SelectRows(Tbl, each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
                Res = Table.PromoteHeaders(No_null_rows)
             ] [Res]),
    Combined = Table.Combine(Pos_of_headrs_and_select_range)
in
    Combined
 
Back
Top