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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
NotebookEnjoyer
Advocate II
Advocate II

USERELATIONSHIP problems with n:m-relationship

Hello everyone,

I have an arrangement as follows:

NotebookEnjoyer_0-1776323987537.png

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:

 

NotebookEnjoyer_1-1776324536294.png

 

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.)

1 ACCEPTED SOLUTION
Abdullahmajid1
Regular 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')
)

View solution in original post

15 REPLIES 15
v-priyankata
Community Support
Community Support

Hi @NotebookEnjoyer 

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.

Xian-Zuo
Frequent Visitor

XianZuo_0-1776836660457.png
you can try this.

measure = 
CALCULATE(
  [Measure]
   ,Map1
)

 

Abdullahmajid1
Regular 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')
)
v-priyankata
Community Support
Community Support

Hi @NotebookEnjoyer 

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.

 

cengizhanarslan
Super User
Super 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] )
    )
_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

Unfortunately this doesn't differentiate correctly for D1.

techies
Super User
Super 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] )
    )
RETURN
    Result
 
 
Power BI & Microsoft Fabric
PL-300 | DP-600 | DP-700 Certified

It's not quite there yet. It doesn't differentiate by the dimension and gives double the correct sum. I'm working on it.

johnt75
Super User
Super 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

Doesn't work, unfortunately. Could it be that the calculated "_Keys"-table does not have the original relationships anymore?

Hi @NotebookEnjoyer 

looks like we need a REMOVEFILTERS due to context transition, can you shar ethe pbix ?

 

Thanks

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

Unfortunately I can't, because the real model contains company data (and rebuilding the whole thing as mock-up does not yet seem proportional).

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.

In short, it works. (In long, I have to add a filter because for each entry there is each one positive and negative entry, canceling each other out, and I have left out of my model the dimension table by which this is filtered. But it works.)

Try

Sum by inactive Relationship =
VAR _Keys =
    CALCULATETABLE (
        VALUES ( 'Fact_2'[Key_F2] ),
        USERELATIONSHIP ( 'Dim_1'[Key_D1], 'Fact_2'[Key_D1] )
    )
VAR Result =
    CALCULATE ( SUM ( 'Fact_1'[Value_F1] ), TREATAS ( _Keys, 'Fact_1'[Key_F2] ) )
RETURN
    Result

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.