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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
simormate
Frequent Visitor

USERELATIONSHIP together with SELECTEDVALUE or RELATED

I have two relationships between two table: a contracts table and a price plans table. The active one is between the current price plan of the contract, and the inactive one is between the price plan at the beginning of the contract (users are allowed to shift between price plans during the contract). I would like to have a calculated column in my contract table showing the name of the first price plan. These codes do not work:

 

First Price Plan =

CALCULATE ( RELATED ( PricePlans[Price Plan] ), USERELATIONSHIP ( Contracts[First Price Plan ID], PricePlans[Price Plan ID]))

 

First Price Plan =

CALCULATE ( SELECTEDVALUE ( PricePlans[Price Plan] ), USERELATIONSHIP ( Contracts[First Price Plan ID], PricePlans[Price Plan ID]))

 

Why do these codes not work and what could work?

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@simormate , USERELATIONSHIP  can change the relationship in the case of measure. In the case of the column, you can simply use your choice of joins in the filter.

example

First Price Plan = minx (filter(PricePlans,Contracts[First Price Plan ID]= PricePlans[Price Plan ID]) PricePlans[Price Plan] )

 

refer : https://www.youtube.com/watch?v=czNHt7UXIe8

View solution in original post

3 REPLIES 3
simormate
Frequent Visitor

An article from sqlbi.com explaining the issue and solutions: https://www.sqlbi.com/articles/userelationship-in-calculated-columns/

amitchandak
Super User
Super User

@simormate , USERELATIONSHIP  can change the relationship in the case of measure. In the case of the column, you can simply use your choice of joins in the filter.

example

First Price Plan = minx (filter(PricePlans,Contracts[First Price Plan ID]= PricePlans[Price Plan ID]) PricePlans[Price Plan] )

 

refer : https://www.youtube.com/watch?v=czNHt7UXIe8

daxer-almighty
Solution Sage
Solution Sage

You are in trouble here. USERELATIONSHIP is not able to change the connection between tables when you use it in a calculated column. Only the active relationship is always active when you define a calculated column. There are articles about this behaviour on www.sqlbi.com

 

What you can do is use LOOKUPVALUE instead.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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