Return Column name of first non null value

orangebloss

Board Regular
Joined
Jun 5, 2013
Messages
51
Office Version
  1. 365
Platform
  1. Windows
Potentially asking for the impossible here! I have a formula that return s the first non null value in a row - what I actually want to do is return the column name,

Power Query:
(List.RemoveNulls(List.RemoveFirstN(Record.ToList(_),4)))
returns the first value correctly, I tried using Table.CoumnNames but it wasn't happy!

any thoughts and suggestions appreciated

The source file is a CSV if that makes any difference
 
Last edited by a moderator:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    tcn = Table.ColumnNames(Source),
    Result = Table.AddColumn(Source, "First Non-null Column", each 
        try
            List.Select(List.Zip({Record.ToList(_), tcn}), (x)=> x{0}<> null){0}{1}
        otherwise
            "N/A")
in
    Result

Book1
ABCDEFGHIJK
1Col1Col2Col3Col4Col1Col2Col3Col4First Non-null Column
229152915Col3
34913549135Col1
436312173631217Col1
54444Col4
63242331332423313Col1
741184118Col1
814947261494726Col1
9N/A
1012251225Col1
112323Col4
123011344630113446Col1
1327512751Col2
141663816638Col1
15
Sheet2
 
Upvote 0
Solution
tcn = Table.ColumnNames(Source), Result = Table.AddColumn(Source, "First Non-null Column", each try List.Select(List.Zip({Record.ToList(_), tcn}), (x)=> x{0}<> null){0}{1} otherwise "N/A")
Hi thanks for this - I'm almost there, the columns I want to look at start at column 5, can you explain the meaning of the numbers in brackets so i can try and figure this out?

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top