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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
olimilo
Post Prodigy
Post Prodigy

Get the first nonblank value from sorted related table?

Given that I have 2 tables A and B related by the CCID, how can I get the first nonblank value from a sorted table B as a calculated column? Table B is sorted using a ranked Status that determines which value would be the result value of the calculated column.

 

I'm unsure if LOOKUPVALUE() recognizes the sort order of the values.

 

For example in the table below, the ones in bold face should be the value of the calculated column:

 

CCID DocumentType Status StatusRank
1000117 Doctype 1 06/14/2023 5
1000117 Doctype 1 Rejected 6
1000117 Doctype 2 06/18/2023 5
1000117 Doctype 3 Uploaded 1
1000117 Doctype 3 Approved 4
1000117 Doctype 4 Approved 4
1000117 Doctype 4 Rejected 5
1000117 Doctype 5 Uploaded 1
1000117 Doctype 6 Uploaded 1
1000117 Doctype 6 Rejected 5
1000117 Doctype 7 Uploaded 1


Edit: Was able to achieve this by adding a grouped Index column in the Table B query and using FIRSTNONBLANK filtering the Table B data to only show the row with the Index = 1, but is there a better solution to this?

1 REPLY 1
lbendlin
Super User
Super User

Correct, LOOKUPVALUE just grabs whatever it finds first.  In general there is no such thing as a sort order in Power BI.  You need to enforce that in your DAX query, via TOPN(1,...) or ORDER BY for example.  And you will have to pay the performance penalty price.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.