The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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?
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.