Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
I'm dealing with a hierarchy in a data cube with various codes with uneven levels which would make custom measures and reporting a nightmare.
The below screenshot is a mockup in Excel just to give a visualization of how the hierarchy looks - would it be possible to create a custom column within the Power BI Query Editor to always pull the lowest item in the hierarchy where available to normalize the levels, like where it reads Custom Column below?
Solved! Go to Solution.
Sure: Just add a column with this formula:
List.Last(List.Select(Record.FieldValues(_), each _ <> null))
It selects the last value from the row's values that is not null.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Sure: You select the fields first that shall be considered:
List.Last(List.Select(Record.FieldValues(Record.SelectFields(_, {ListOfColumnNames})), each _ <> null))
... unfortunately the latest code editor doesn't allow any custom code highlighting any more, but the addition is happening on the innermost level of the formula: Record.SelectFields(_, {ListOfColumnNames})
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Sure: Just add a column with this formula:
List.Last(List.Select(Record.FieldValues(_), each _ <> null))
It selects the last value from the row's values that is not null.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Actually, is there a way to refine the custom column a bit more to select the last from amongst certain columns? I just noticed that upon adding additional columns, it would confuse things and start pulling the last column added instead of from the original hierarchy.
Sure: You select the fields first that shall be considered:
List.Last(List.Select(Record.FieldValues(Record.SelectFields(_, {ListOfColumnNames})), each _ <> null))
... unfortunately the latest code editor doesn't allow any custom code highlighting any more, but the addition is happening on the innermost level of the formula: Record.SelectFields(_, {ListOfColumnNames})
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
That worked out perfectly, thanks!
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.