Forum Discussion
USERELATIONSHIP problems with n:m-relationship
Hello everyone,
I have an arrangement as follows:
Therein, the following measure unfortunately yields blank values:
Sum by inactive Relationship = SUMX(
VALUES('Fact_2'[Key_F2]),
CALCULATE(
SUM('Fact_1'[Value_F1]), // Any aggregation really
USERELATIONSHIP(
'Dim_1'[Key_D1],
'Fact_2'[Key_D1]
)
)
)
The goal is a table/matrix visual like this:
My best guess is that if I force to use the inactive relationship, it is unclear which other relationship is to be ignored?
ChatGPT recommended:
Sum F1 by F2 =
CALCULATE(
SUM('Fact_1'[Value_F1]),
TREATAS(
VALUES('Fact_2'[Key_D1]),
'Fact_1'[Key_D1]
)
)
This gives a value for the sum, but only one with a blank Key_D1, not differentiating.
Thanks for any help! (And please, if you write DAX code, I would really appreciate at least some formatting and not colossal one-liners.)
Try this:
Sum F1 by F2 := CALCULATE( SUM('Fact_1'[Value_F1]), TREATAS( VALUES('Fact_2'[Key_D1]), 'Fact_1'[Key_D1] ), REMOVEFILTERS('Map1') )
15 Replies
- techiesSuper User
Hi NotebookEnjoyer please try this
Sum by inactive Relationship = VAR _CurrentKey = SELECTEDVALUE ( 'Dim_1'[Key_D1] )VAR _Keys =CALCULATETABLE (VALUES ( 'Fact_2'[Key_F2] ),TREATAS ( { _CurrentKey }, 'Fact_2'[Key_D1] ))VAR Result =CALCULATE (SUM ( 'Fact_1'[Value_F1] ),TREATAS ( _Keys, 'Map1'[Key_F2] ))RETURNResult- NotebookEnjoyerAdvocate II
It's not quite there yet. It doesn't differentiate by the dimension and gives double the correct sum. I'm working on it.
- cengizhanarslanSuper User
Please try the measure below:
Sum by inactive Relationship = VAR _Keys = VALUES( 'Fact_2'[Key_D1] ) RETURN CALCULATE( SUM( 'Fact_1'[Value_F1] ), TREATAS( _Keys, 'Dim_1'[Key_D1] ) )- NotebookEnjoyerAdvocate II
Unfortunately this doesn't differentiate correctly for D1.
- johnt75Super User
Not sure if this will work but you could try
Sum by inactive Relationship = VAR _Keys = CALCULATETABLE ( VALUES ( 'Fact_2'[Key_F2] ), USERELATIONSHIP ( 'Dim_1'[Key_D1], 'Fact_2'[Key_D1] ) ) VAR Result = SUMX ( _Keys, CALCULATE ( SUM ( 'Fact_1'[Value_F1] ) ) ) RETURN Result- NotebookEnjoyerAdvocate II
Doesn't work, unfortunately. Could it be that the calculated "_Keys"-table does not have the original relationships anymore?
- johnt75Super User
I don't think that that is the problem.
Can you create a measure like
Test Sum = SUMX ( 'Fact_2', CALCULATE ( SUM ( 'Fact_1'[Value_F1] ) ) )and put that into a table / matrix with 'Fact_2'[Key_D1]. This isn't using the inactive relationship at all so should tell us if the active relationships are working as intended.
- v-priyankataCommunity Support
Thank you for reaching out to the Microsoft Fabric Forum Community.
johnt75 techies cengizhanarslan FBergamaschi Thanks for the inputs.
I hope the information provided by users was helpful. If you still have questions, please don't hesitate to reach out to the community.
- Abdullahmajid1Regular Visitor
Try this:
Sum F1 by F2 := CALCULATE( SUM('Fact_1'[Value_F1]), TREATAS( VALUES('Fact_2'[Key_D1]), 'Fact_1'[Key_D1] ), REMOVEFILTERS('Map1') ) - Xian-ZuoFrequent Visitor
you can try this.measure = CALCULATE( [Measure] ,Map1 ) - v-priyankataCommunity Support
Hope everything’s going smoothly on your end. I wanted to check if the issue got sorted. if you have any other issues please reach community.