Forum Discussion

Sergiy's avatar
Sergiy
Resolver II
2 years ago
Solved

LOOKUPVALUE: a bug or a feature

I've worked with Power BI for many years and used LOOKUPVALUE function blissfully unaware of its hidden pitfall. It seems that this function is not always reliable. There are cases when LOOKUPVALUE ...
  • OwenAuger's avatar
    2 years ago

    Hi Sergiy 

    • First of all, I agree that Microsoft's LOOKUPVALUE documentation is severely lacking in describing how existing filters are handled. I had previously believed that it ignored all filters when carrying out itse search, but that is clearly not the case!
    • If we rely on SQLBI's description of the function and the "equivalent syntax", then ALL ( <Table_Result_ColumnName> ) would remove all filters on the expanded table containing the result column.
    • In your model, the expanded 'Projects' table is just the 'Projects table itself (since all related tables are on the many-side of 1:many relationships with 'Projects').
    • So ALL ( 'Projects' ) removes all filters on the 'Projects' table itself. But it does not remove filters on ProjProg_Ids or Programs which can filter 'Projects' via the bidirectional relationship between ProjProg_Ids and Projects. It would have to internally apply ALLCROSSFILTERED ( 'Projects' ) in order to remove all filters that could affect 'Projects'.
    • A possible rewriting of the LOOKUPVALUE measure in this case could be this (which is pretty awkward):

     

    _projectName_LOOKUPVALUE_Fixed = 
    VAR LookupProjectID =
        SELECTEDVALUE('Dependencies'[ProjectId])
    RETURN
        CALCULATE (
            LOOKUPVALUE(
                Projects[Project Name], 
                Projects[Id], 
                LookupProjectID
            ),
            ALLCROSSFILTERED ( Projects )
        )

     

    What would I take away from this?

    • LOOKUPVALUE is a risky function to use at the best of times, as it does not ignore all filters that could impact the table containing the result column (specifically filters from tables on the many-side of bidirectional relationships).
    • Microsoft's documentation is lacking and should be updated (I've just placed some feedback myself).
    • Personally, I would avoid LOOKUPVALUE in favour of other methods such as the examples you created.
    • It would be good to understand the source of SQLBI's "equivalent syntax". It might be worth placing feedback on either of these pages: