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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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))









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


Proud to be a Super User!









"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))









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


Proud to be a Super User!









"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

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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