Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
PC20
Frequent Visitor

Get the latest non-null value from a list of columns.

There are few columns in data. I want to get the latest non-null value from these columns. 

The NewOutputCol is my output column.

In first row, L1 column has the latest non-null value and therefore, output is "A".

In second row, L2 column has the latest non-null value and therefore, output is "E".

In thirs row, L3 column has the latest non-null value and therefore, output is "Z".


In real data, I have 10 such columns to scan from and over 90,000 rows.

 

Sample data:

L1L2L3NewOuputCol
AnullnullA
DEnullE
XnullZZ
1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @PC20 

 

In Power Query, you can create this custom column

List.Last(List.Select(Record.FieldValues(_), each _ <> null))




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

2 REPLIES 2
danextian
Super User
Super User

Hi @PC20 

 

In Power Query, you can create this custom column

List.Last(List.Select(Record.FieldValues(_), each _ <> null))




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Greg_Deckler
Super User
Super User

@PC20 Probably best if you unpivot your columns and add and index perhaps. Otherwise, maybe this:

Column = 
    VAR __Data = [L1] & "|" & [L2] & "|" & [L3]
    VAR __Table = 
        ADDCOLUMNS(
            GENERATESERIES(1,3,1),
            "__Data", PATHITEM(__Data,[Value],TEXT)
        )
    VAR __Max = MAXX(FILTER(__Table,[__Data] <> BLANK()),[Value])
    VAR __Result = MAXX(FILTER(__Table,[Value] = __Max),[__Data])
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.