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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
chat_peters
Helper III
Helper III

One Slicer to respond to two different columns in the same fact table

Hello, I have a question about userelationship function, I've been tasked with having one filter respond to two different columns in the same table 😞
I have four tables in my model. Orderfact, CallerDim, BuyerDim and People Dim. The ask is to be able to pick a location from people fact and have it respond to both columns in order fact. For example say if
order ID 1 - Caller is from Lima and the Buyer is from Guadalajara
order ID 2 - the Caller is from Guadalajara and the buyer is from Leon
Order ID 3 - Caller and Buyer are both from Guadalajara. When I choose Guadalajara from the location filter it should be able to pick up all three of the records. 

Currently I can achieve this by creating a measure with userelationship,

 

inactiverelationshipmeasure = CALCULATE('Order Fact'[Total Orders],USERELATIONSHIP('Order Fact'[BuyerID],'PeopleDim'[Id]))

 

However, in order for the filter to respond to both columns in the same table, I need to drag this measure and Total Orders measure on to the canvas

 

Total Orders = COUNT('Order Fact'[Order ID])

 

I need to create a measure or a flag so that my visual doesn't look confusing. For example the total number of rows in the visual in the picture should be 14, how do I achieve that? Can you please help me? I've tried filter, calculatetable, nothing seems to give me the count of 14 I need. I need a count where either caller is from the selected loation or the buyer is from the selected location or both are from the selected location. Can someone please help me?

datamodel.PNGVisual.PNG

2 ACCEPTED SOLUTIONS
johnt75
Super User
Super User

You could try

Total Orders =
var chosenLocations = VALUES( 'PeopleDim'[Location])
return CALCULATE( SUMX('Order Fact'), IF( RELATED( 'CallerDim'[Location]) IN chosenLocations ||
RELATED( 'BuyerDim'[Location]) IN chosenLocations,
1),
REMOVEFILTERS('PeopleDim'[Location])
)

View solution in original post

Not sure if this will work but you can try

Total Orders =
var buyerOrders = CALCULATETABLE( VALUES('Order Fact'[Order ID]), 
   USERELATIONSHIP( 'Order Fact'[BuyerID], 'PeopleDim'[Id])
)
var callerOrders = CALCULATETABLE( VALUES('Order Fact'[Order ID]), 
   USERELATIONSHIP( 'Order Fact'[CallerID], 'PeopleDim'[Id])
)
var allOrders = DISTINCT( UNION( buyerOrders, callerOrders))
return CALCULATE( SUMX('Order Fact', 1), REMOVEFILTERS( 'PeopleDim'), 
   TREATAS( allOrders, 'Order Fact'[Order ID])
)

View solution in original post

7 REPLIES 7
chat_peters
Helper III
Helper III

This works perfect. I was agonizing over measure created with userelationship. Now I have to go back and do more research on removefilters! Thank you so so so much 😊

johnt75
Super User
Super User

You could try

Total Orders =
var chosenLocations = VALUES( 'PeopleDim'[Location])
return CALCULATE( SUMX('Order Fact'), IF( RELATED( 'CallerDim'[Location]) IN chosenLocations ||
RELATED( 'BuyerDim'[Location]) IN chosenLocations,
1),
REMOVEFILTERS('PeopleDim'[Location])
)

@johnt75 The solution you provided would have worked wonderful if I was not on direct query mode. I am not allowed to do in. Also I built this solution in power bi, but in reality the model is in SSAS, direct query mode. So I can't use lookup to get the location to populate in the buyer table. I can try related, however, userelationship only works inside of calculate. How can I go about populating the location in buyer dim using userelationship? Also is there a work around to using IN? thank you in adavance for taking your time to read this post.

Not sure if this will work but you can try

Total Orders =
var buyerOrders = CALCULATETABLE( VALUES('Order Fact'[Order ID]), 
   USERELATIONSHIP( 'Order Fact'[BuyerID], 'PeopleDim'[Id])
)
var callerOrders = CALCULATETABLE( VALUES('Order Fact'[Order ID]), 
   USERELATIONSHIP( 'Order Fact'[CallerID], 'PeopleDim'[Id])
)
var allOrders = DISTINCT( UNION( buyerOrders, callerOrders))
return CALCULATE( SUMX('Order Fact', 1), REMOVEFILTERS( 'PeopleDim'), 
   TREATAS( allOrders, 'Order Fact'[Order ID])
)

Brilliant! I've been using the filter function in all different ways. You've encouraged me to learn more about variables. Thank you so much. It works in my power bi. I hope it works in SSAS tabular model🤞

amitchandak
Super User
Super User

@chat_peters , You can use an independent table and filter both


calculate([Total Orders] filter('Order Fact','Order Fact'[BuyerID] in values('PeopleDim'[Id]) || 'Order Fact'[CallerID] in values('PeopleDim'[Id]) ))

@amitchandak Thank you for taking your time to respond. Unfortunately the measure only looks at records where the caller is from the selected location or the caller and buyer are both from the selected location. Thank you for pointing me in a different direction, I am going to try a few things with your measure 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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