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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
olimilo
Continued Contributor
Continued Contributor

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors