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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
JeanMartinL
Advocate II
Advocate II

Filtering with an active relationship while grouping with an inactive relationship

Hello everyone,

 

I'm trying to slice and dice data using both an active and inactive relationship at the same time and I feel like I'm missing something.

I've created a very simple example to illustrate my issue. I feel like this should be a pretty commun scenario.

 

2 Tables: Location and Movement. Location is a simple ID/Name list while Movement has FromLocationID, ToLocationID and Quantity. There are 2 relationships between the tables, the active relationship is on FromLocationID and ToLocationID is inactive.

 

JeanMartinL_0-1691780044065.pngJeanMartinL_1-1691780062125.png

JeanMartinL_2-1691780076965.png

 

What I'm trying to do sounds pretty simple. I simply want to filter on the FromLocation (using a slicer for example) and then have the results grouped by ToLocation.

 

Here is what I have done so far:

JeanMartinL_4-1691781551864.png

 

I wonder if I can somehow create a measure that filters first using the active relationship and then applies the grouping using USERELATIONSHIP as a second step but I have no idea how that would work.

 

The only "solutions" I can think of now are pretty bad IMO .

1) Doubling the Location table so that I can have a active relationship per column.

2) Creating calculated columns with RELATED to have the LocationName directly in Movement

 

Keep in mind that this is a contrived example so that it's simpler to understand. In the real model the "Location" table is a large dimension with many fields and other relationships, so doubling the table or copying fields in the fact table is not really an option.

 

Thanks for the help!

2 REPLIES 2
Anonymous
Not applicable

Hi @JeanMartinL ,

 

Please create a new table for slicer:

Table = 'Location'

Model:

vcgaomsft_0-1691996239217.png

Then create a new measure:

Tottal Quantity =
VAR __location_id =
    CALCULATETABLE (
        VALUES ( 'Table'[LocationID] ),
        ALLSELECTED ( 'Table'[LocationName] )
    )
VAR __to_location_id =
    CALCULATETABLE (
        VALUES ( 'Movement'[ToLocationID] ),
        FILTER ( ALL ( 'Movement' ), 'Movement'[FromLocationID] IN __location_id )
    )
RETURN
    IF (
        MAX ( 'Location'[LocationID] ) IN __to_location_id,
        CALCULATE (
            SUM ( Movement[Quantity] ),
            'Movement'[FromLocationID] IN __location_id,
            USERELATIONSHIP ( 'Location'[LocationID], 'Movement'[ToLocationID] )
        )
    )

Output:

vcgaomsft_1-1691996310801.png

vcgaomsft_2-1691996324067.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Hello @Anonymous 

 

Thank you for the response. This indeed works in this contrived example, but I feel it would be inelegant in a real model / report.

 

Since we need to use that copy of Location for the slicer and that it only affects a single measure, it means that all other visuals will not be filtered by it (especially if we are filtering other fact tables). I fell it also add a lot of confusion into the model.

 

If I were to add a copy of a table, I would rather create a “LocationDestination” table with a relationship to “ToLocationID”, I believe this would be slightly clearer and could still work with the basic Slicer on “Location”.

Still, I want to thank you for that measure, it is some impressive DAX work, and I could see it being useful.

 

Thanks!

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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