Search code examples
indexingfindpowerquerylookup

Find value and column header


I have an issue that is going me crazy about power query excel. I have a table with several columns and I want to find the, e.g., the first non-null value for each row. It is OK, I can do that with the usual way: Table.AddColumn(#"Previous", "NotNull" each List.First(List.RemoveNulls({ColA,ColB,ColC}))) but I am struggling trying to find in which column appears.

I tried combinations of Table.ColumnNames and similar with no result. The raw solution with nested if's checking column by column doesn't please me.

I can do that with no effort in R/Python but I'd like to that in PQ excel.

Can anyone give me a clue? Is there any function that I'm missing?


Solution

  • Use the Table.ColumnNames function to get a list of the column names in your table.

    Then use the List.PositionOf function to find the index of the first non-null value in each row.

    Sources: Table.ColumnName and List.PositionOf