March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Dear Power BI Community !
I am trying to feed a calculated column using an inactive relationship.
The idea is have an equivalent of RELATED between two tables that have inactiv relationship to feed a calculated column.
Any idea of how to do it ?
best !
Solved! Go to Solution.
@Olenard , In the case of a column related, will not work with inactive relation, and use relation might not work well.
You can use lookupvalue or can use a formula like this
City Name = maxx(FILTER(geography,geography[City Id]=Sales[City Id]),geography[City])
refer to this video : https://www.youtube.com/watch?v=czNHt7UXIe8
@Anonymous
Of course you can change the active relationship when doing calculations in a table. For instance, if you have a simple model like:
with the relationship inactive, you can create the calculated column:
Res = CALCULATE(SUM(Table1[Col1]), USERELATIONSHIP(DimT[Col1],Table1[Col1]))
on table DimT, which will work fine using the otherwise inactive relationship.
It is true that it won't work with RELATED( ) as I suggested earlier but that has nothing to do with USERELATIONSHIP( ) but rather with CALCULATE( ). RELATED( ) requires a row context and that will be lost through context transition when using CALCULATE( ). A calc column in Table1 such as:
New col = CALCULATE( RELATED(DimT[Col2]) )
with the an active relationship will not work either, precisely for that reason, while this would:
New col = RELATED( DimT[Col2] )
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
If you show the details your code (that iterative (line by line) formula) and/or provide more info on the model, ideally sharing the pbix, perhaps we can find a less resource-heavy solution.
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Hi !
I used a variable that provided a 'true'/'flase'. This is working fine with calculate then.
Next step to be able to 'store' this value and return the value in the return statement.
@Anonymous
Of course you can change the active relationship when doing calculations in a table. For instance, if you have a simple model like:
with the relationship inactive, you can create the calculated column:
Res = CALCULATE(SUM(Table1[Col1]), USERELATIONSHIP(DimT[Col1],Table1[Col1]))
on table DimT, which will work fine using the otherwise inactive relationship.
It is true that it won't work with RELATED( ) as I suggested earlier but that has nothing to do with USERELATIONSHIP( ) but rather with CALCULATE( ). RELATED( ) requires a row context and that will be lost through context transition when using CALCULATE( ). A calc column in Table1 such as:
New col = CALCULATE( RELATED(DimT[Col2]) )
with the an active relationship will not work either, precisely for that reason, while this would:
New col = RELATED( DimT[Col2] )
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
"Of course you can change the active relationship when doing calculations in a table". Of course, you can't, @AlB. We're talking here about RELATED in fact and USERELATIONSHIP can't change the connection in a table (calculated column) in a way that RELATED work how one would expect it; hence you have to use LOOKUPVALUE. There's an article about it on www.sqlbi.com and in their book as well , as I mentioned. Here's something you SHOULD read: https://www.sqlbi.com/articles/userelationship-in-calculated-columns/
Sorry but you can't change the active relationship when doing calculations in a table. USERELATIONSHIP will have no effect. Your best function to do what you want is LOOKUPVALUE. It's not only the best one. IT'S THE ONLY ONE. You'll find the explanation of this behaviour in one of the articles on www.sqlbi.com.
@Olenard , In the case of a column related, will not work with inactive relation, and use relation might not work well.
You can use lookupvalue or can use a formula like this
City Name = maxx(FILTER(geography,geography[City Id]=Sales[City Id]),geography[City])
refer to this video : https://www.youtube.com/watch?v=czNHt7UXIe8
Great one ! The only thing is that this is an iterative (line by line) formula. Then quite resource consuming!
But if there is no solution with an inactive relationship (seems like it does not work with the calculated column), this is the solution
Hi @Olenard
Just use USERELATIONSHIP to activate the relationship and then RELATED as usual
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Hi,
Do you have an example. Because to use USERELATIONSHIP you need to use caculate. Not made to display a text value
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
23 | |
15 | |
12 | |
9 | |
8 |
User | Count |
---|---|
41 | |
32 | |
29 | |
12 | |
12 |