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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Joe_Marangos
Frequent Visitor

USERELATIONSHIP not working as expected. Could use some suggestions.

Hi all,

Im working on a report that invovles interactive mapping. The complexity with the project is that there are different legends for different data layers which means I have to use a table to get a working legend. 

 

I have two key tables: Legend_Table and Pollution_Data. 

 

I have a slicer that switches the map data (which is using Pollution_Data) between NO2 and NOX.

 

Within these tables I need the following relationships established for filtering:

 

Legend_Table[Cat] <-> Pollution_Data[NO2_Cat]

Legend_Table[Cat] <-> Pollution_Data[NOX_Cat]

 

Legend_Table[Cat] contains all the values that would match with either the NO2_Cat or NOX_Cat collumns. 

 

Obviously, connecting these relationships and trying to make them both active does not work. So I have been attempting to use "USERELATIONSHIP" to switch between the relationships depending on the data selected. 

 

As a test run I did one active relationship like this for "Legend_Table[Cat] <-> Pollution_Data[NO2_Cat]":

Joe_Marangos_0-1652102300903.png

Which means that the table is filtered down to just the NO2 catageories and Hex codes:

Joe_Marangos_1-1652102390887.png

And also allows me to click an item in the table to filter down the map to just those categories (the map is using Pollution_Data):

Joe_Marangos_2-1652102468971.png

However, I have a switch that lets users change between NO2 and NOX but I want to maintain the legend interactivity. To do this I create two inactive relationships for NO2 and NOX as so (note the screenshot is incorrect but both relationships are both ways):

Joe_Marangos_3-1652102555677.png

Then I make a switch like this:

 

 

LegendSwitch = SWITCH([Selection],
1,CALCULATION(COUNT(Pollution_Data[NO2_Cat]),USERELATIONSHIP(LegendTable[CAT],Pollution_Data[NO2_Cat])),
2,CALCULATION(COUNT(Pollution_Data[NOX_Cat]),USERELATIONSHIP(LegendTable[CAT],Pollution_Data[NOX_Cat])))

 

 

Now this works for filtering the table (or legend, as its intended as in this case) so that NO2 and NOX selections result in different values:

Joe_Marangos_4-1652103018447.pngJoe_Marangos_5-1652103039462.png

However, when clicking a category in the legend table like before, the map no longer filters:

Joe_Marangos_0-1652103770764.png

 

I thought that USERELATIONSHIP would make the relationships function in exactly the same way but just switch according to what was selected in the slicer. What am I missing here? Are there any other methods that can be used to achieve a similar outcome?

 

Thanks in advance,

Joe

 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Joe_Marangos ,

As the relationship only active in the measure calculation, NO2_Cat and NOX_Cat can't be filtered by the Legend_Table, they don't actually have a relationship.

For your purpose, the data model should be modified or create a new table.

Method1.

In Power Query, unpivot the NO2_Cat and NOX_Cat columns.

vkalyjmsft_0-1652421199176.png

They'll be in one column, so it's easy to build relationships.

vkalyjmsft_1-1652421312227.png

Method2.

Create a new table, separate NOX_Cat.

 

NOX_Cat Table = SELECTCOLUMNS('Pollution_Data',"NOX_Cat",'Pollution_Data'[NOX_Cat])

 

Both tables are related to Legend_Table.

vkalyjmsft_2-1652421717362.png

This is an overall idea, the specific operation should be combined with your sample.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @Joe_Marangos ,

As the relationship only active in the measure calculation, NO2_Cat and NOX_Cat can't be filtered by the Legend_Table, they don't actually have a relationship.

For your purpose, the data model should be modified or create a new table.

Method1.

In Power Query, unpivot the NO2_Cat and NOX_Cat columns.

vkalyjmsft_0-1652421199176.png

They'll be in one column, so it's easy to build relationships.

vkalyjmsft_1-1652421312227.png

Method2.

Create a new table, separate NOX_Cat.

 

NOX_Cat Table = SELECTCOLUMNS('Pollution_Data',"NOX_Cat",'Pollution_Data'[NOX_Cat])

 

Both tables are related to Legend_Table.

vkalyjmsft_2-1652421717362.png

This is an overall idea, the specific operation should be combined with your sample.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

MFelix
Super User
Super User

Hi @Joe_Marangos ,

 

Is the chart also done based on the USERELATIONSHIP formula or is it based on a different one?

 

Can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

If the information is sensitive please share it trough private message.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.