Forum Discussion

Zyg_D's avatar
Zyg_D
Continued Contributor
6 years ago

USERELATIONSHIP does not work on one-to-one

The function USERELATIONSHIP nicely works when the top right relationship is one-to-many. But when I change it to one-to-one, the USERELATIONSHIP does not yield correct results. Why? It should not be affected at all, in my opinion. 

Data:

Relationships (one-to-many):

Formula when one-to-many (correct result):

Relationships (one-to-one):

Formula when one-to-one (incorrect result):

 

4 Replies

  • Hi Zyg_D ,

     

    This is related with the way that the USERELATIONSHIP works, the function is used as a context transaction and the calculated columns force this to be a row context so the calculation will give inacturated values.

     

    Check the blog post of SQL BI with a full detail on this, and that suggest in this case the use of LOOKUPVALUE or the use of CALCULATETABLE depending on expected results.

     

    https://www.sqlbi.com/articles/userelationship-in-calculated-columns/

  • Zyg_D first and foremost question, since this relationship is active, not sure why you are using USERELATIONSHIP, and 2nd you don't need to use MAX function, you can simply use RELATED function to get value from One side of the relatioship.

     

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.

    • Zyg_D's avatar
      Zyg_D
      Continued Contributor

      parry2k wrote:

      Zyg_D first and foremost question, since this relationship is active, not sure why you are using USERELATIONSHIP, and 2nd you don't need to use MAX function, you can simply use RELATED function to get value from One side of the relatioship.

      In the USERELATIONSHIP I am trying to use the bottom right relationship. However, I see that the top right one affects my results, which is bizzare.