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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Jeffery24
Helper I
Helper I

Finding the last Column Name with populated values

Hi. 


Have been searching for awhile but cannot find a solution.

I'm trying to obtain the column name that has the last populated value in a row.
The dataset is a set of events in sequential order, not date order.

Unfortunately our dataset is column based and not unpivoted ( a restriction by IT).
Below is a snapshot of the data.

Jeffery24_0-1712938752445.png

I am looking to find the value and name of the last event that is populated

I have managed to obtain the value of the last event and added a column "Custom".

= Table.AddColumn(AddTable, "Custom", each List.Last(List.Select(Record.FieldValues(_), each _ <> null)))

 This works well but I am unable to find a similar formula to return the header name.
E.g. row 1142 should return "RIW_FGO_OFD_Last,
row 1144  should return "REW_FGI_Last.
Is this possible without unpivoting the table?
Many thanks.

1 ACCEPTED SOLUTION
m_dekorte
Super User
Super User

Hi @Jeffery24,

 

You can give this a go:

 

= Table.AddColumn(AddTable, "Custom", each Table.Last( Table.SelectRows( Record.ToTable(_), each [Value] <> null ))[Name])

 

Alternatively, this will do the trick as well

 

= Table.AddColumn(AddTable, "Custom", each Record.FieldNames(_){List.PositionOf(Record.FieldValues(_), List.Last(List.RemoveNulls(Record.FieldValues(_))))} )

 

Or implemented as custom function (2 steps)

 

getFieldName = (r as record) as text =>
    Record.FieldNames(r){List.PositionOf(Record.FieldValues(r), List.Last(List.RemoveNulls(Record.FieldValues(r))))},
InvokeFunction =  Table.AddColumn(AddTable, "Custom", each getFieldName(_) )

 

I hope this is helpful 

View solution in original post

2 REPLIES 2
m_dekorte
Super User
Super User

Hi @Jeffery24,

 

You can give this a go:

 

= Table.AddColumn(AddTable, "Custom", each Table.Last( Table.SelectRows( Record.ToTable(_), each [Value] <> null ))[Name])

 

Alternatively, this will do the trick as well

 

= Table.AddColumn(AddTable, "Custom", each Record.FieldNames(_){List.PositionOf(Record.FieldValues(_), List.Last(List.RemoveNulls(Record.FieldValues(_))))} )

 

Or implemented as custom function (2 steps)

 

getFieldName = (r as record) as text =>
    Record.FieldNames(r){List.PositionOf(Record.FieldValues(r), List.Last(List.RemoveNulls(Record.FieldValues(r))))},
InvokeFunction =  Table.AddColumn(AddTable, "Custom", each getFieldName(_) )

 

I hope this is helpful 

Hi @m_dekorte 

 

First option works perfectly. You're a legend. Made my week many thanks 🙂

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 MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Kudoed Authors