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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
emilypoon
Advocate I
Advocate I

DAX - USERELATIONSHIP for slicers

Hi,

 

I would like to get a help on setting up a USERELATIONSHIP function to activate a slicer.

 

Here is my data model with 3 records only (Table name = QuantityTable).

The table contains 4 columns with 2 columns are date-related -> OrderDate and DeliveryDate

image.png

 

Then, I set up a MasterCalendar table with the CALENDAR function.

image.png

 

Now I have 2 tables in my model -> QuantityTable and MasterCalendar.

I linked up the relationship by connecting "Date" from the MasterCalendar table with the "OrderDate" & "DeliveryDate" column from the QuantityTable. The solid line represents an active relationship and I set it as the "OrderDate"

image.png

 

 

I created DAX formula with USERELATIONSHIP to calculate the "Quantity by Order Date" and "Quantity by Delivery Date". The formula works perfectly in a card visual or line/bar visuals etc.

In the below example, if I choose Month=3 from the MasterCalendar slicer, it gives me the below result with "Blank" by OrderDate and "10" by DeliveryDate which is perfect.

image.png

 

Now, I want to create a new slicer with "Item" as follow.

image.png

I want the "Item" slicer to dynamically displays the available fruit names based on "DeliveryDate".

For examplem, I only want the "Item" slicer to display "Apple" if I choose Month=3 based on "DeliveryDate".

I know the active relationship falls to "OrderDate" as per the model setup, but now I want to activate "DeliveryDate" in here instead of "OrderDate".

If I choose Month=3 now, the "Item" slicer will become blank because this slicer only recognize the active relationship of "OrderDate" but not the "DeliveryDate".

As you can see in the below screen shot, the card visual of "Quantity by Delivery Date" is 10 if the month is March, while everything in the "Item" filter is disappeared because it recognizes "DeliveryDate" of March has no record.

image.png

 

I tried to google around to see how I can activate an "inactive relationship" for a slicer but not able to solve this problem. I know I can use USERELATIONSHIP to activate an "inactive relationship" but that is only workable for other non-slicer visuals. How can I do the same for a slicer so that the "Item" slicer would be able to display based on "DeliveryDate"?

 

Appreciate if anyone can suggest anything that is workable for the above scenario.

Thank you so much!

 

Best regards,

Emily

 

 

 

 

12 REPLIES 12
Anonymous
Not applicable

I resolved this by placing the following measure in the "Filters on this Visual" on the slicer

ApplyToFilterVisual = if(Quantity[Quantity by Delivery Date]>0, [Quantity by Delivery Date], Quantity[Quantity by Order Date])
 
The value on filter is set to greater than zero
ItemSlicerFilter.PNG
 
The Slicer is the Item[Items] and the relationship cardinality is Single
 
 ItemSlicer.PNG
 
 
parry2k
Super User
Super User

@emilypoon  First of all great job on explaining the problem. Well done!!

 

Unfortunately, I don't think there is any solution available at this time the way your model is setup. You should have sepereate table for items which should have relatoinship with your quantity table and then slicer should use Item from new items table.

 

It will show all the Items  regardless which month you use. This will be as close as you can get at this point. Instead of showing no item in the slicer, it will show you all the items.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks for your reply @parry2k !

I can create a new table only for "Item" and make it as a slicer, but it will show the same wrong result because I cannot remove the relationship with the MasterCalendar table.

Here is what I did - create a new Table called "ItemTable" with "ItemName" column.

image.png

 

Link the ItemTable with the QuantityTable with relationship.

image.png

 

 

In the report page, add a new slicer for "ItemName" from the ItemTable (see the PINK slicer).

image.png

 

If I filter Month=3, you can see that everything from the "ItemName" slicer is still disappeared because it is still recognizing the "OrderDate" as the active relationship instead of "DeliveryDate".

image.png

 

In this case, how can I activate the "DeliveryDate" field if I create a seperate slicer for "ItemName"?

I can't remove the relationship between MasterCalendar and QuantityTable because I really need that in my real case. Do you know any other DAX formulas that can be used to activate the "ItemName" slicer dynamically based on the date column that I want?

 

 

@emilypoon change your cross filter direction to single between item and quantity table. Double click on relationship and that is where you you change the direction from both to single.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi Emily,

 

Thanks for detailed explaination.

 

Here is the alternate methodSolution

 

Let me know if this works!

@Anonymous Thank you for proposing a great solution with demo file too!! Appreciated a lot!

 

I just tested your solution in my dummy file and it works perfectly (with the support of Power Query too to transform the ItemTable to your format), so I also tested the same in my real company files and it also worked well.

However, the limitation here is that the "Item" slicer will always display all the options and cannot dynamically display only the relevant items given for a specific date (ie. Apple / Orange / Cherry / Banana will always show in the slicer regardless to OrderDate or DeliveryDate.

 

In my real product, I will have 8 sets of different dates with over 10 columns for "items" which is far more complicated than my dummy example.

Is there a way to only display the relevant items in the filter instead of showing all of them?

 

In addition, I created a separate model in Power Query for data transformation and I am not sure if this will affect the performance and speed if we have millions of data record to be filtered by the users.

 

Anonymous
Not applicable

Hi emilipoon, Thanks for your feedback! I think data is displaying correctly.

 

We are filtering on month, in my file I made same month order date & delivery date i.e. June2019.

That is why when you select June they show both Cherry and Orange. If there are no order with same order/delivery month then items will be reflected according to relevant date type.

 

Please show exactly the problem you are facing with pics to understand in better.

 

Thanks

NSRSHKH

 

 

 

@Anonymous Thanks for your feeback and sorry for my late reply.

Your proposed solution is a workaround that works for the slicer only, but in my real case I will have over 20 charts linking to each slicer.

Even if the data can be displayed properly in the slicer by transforming the data into a separate table, but that won't give the correct result if I also have chart visuals.

 

Here I am adding 2 charts in my example.

image.png

 

If I choose Month=3, the top chart of couse will be blank because it is based on "OrderDate" as the active relationship and there is no March data based on OrderDate.

In the bottom chart, it displays the bar for "Apple" if Month=3.

image.png

 

 

However, if I unfilter all the slicers, the bottom chart will always display 2 bars based on the below settings as I put both "Item" and "Quantity" column from the QuantityTableTranform.

image.png

 

 

The problem is that I cannot choose "Quantity" column from the original "QuantityTable" because the chart will still be a blank due to active relationship of "OrderDate"

 

image.png

 

In view of the above problems, do you have any other alternatives in order to show all the items in the slicer and the chart simultaneously given that we have multiple "dates" column?

 

Best regards,

Emily

 

Anonymous
Not applicable

@emilypoon 

 

I am still not getting your requirement.

1) If you select Month=3, you want to display the "Apple" in Item slicer and Chart.

2) If no Month slicer item is selected then all fruits will be displayed in Item slicer and chart based on Order Date will be displayed.

 

Is this what you need? If yes then

 

 

Total Quantity By Order Date = CALCULATE(SUM(QuantityTable2[Quantity]),QuantityTable2[DateType] ="OrderDate")
Total Quantity By Delivery Date = CALCULATE(SUM(QuantityTable2[Quantity]),QuantityTable2[DateType] ="DeliveryDate")
TryThisMeasure = IF(ISFILTERED('Date'[Month]),SUM(QuantityTable2[Quantity]),[Total Quantity By Order Date])

 

 

Use "TryThisMeasure" instead of Quantity in Value section of Chart Visual.

 

Scenario1.pngScenario2.png

 

Hope this resolves your issue. If yes then please mark this as Solution. Thanks

 

@Anonymous  Thank you for your reply and proposed solution.

I understand your workarounds but this is limited in certain situations, especially my real project contains over 20+ slicers similar to "items" and over 10+ "date related" columns that need to be displayed dynamically in both of the slicers and charts.

 

I tried to search from PBI community and here below posts is a reference case which is exactly the same problem to what I am currently facing:

https://community.powerbi.com/t5/Desktop/Slicer-Filters-reflect-quot-Active-quot-data-relationship-when/td-p/423632

 

Do you have any other ways to solve this problem?

Sorry to borther you again and I really appreciated your great help on this, thanks!

 

 

Anonymous
Not applicable

@emilypoon 

 

Solutions are provided based on the query.

I saw the other query you provided link for and that way is not possible in current data arrangement.

 

However you can modify your current DAX to suit my solution.

I might guide you however I would need entire sample data with visuals arrangements to see the effect of one on other.

 

Thanks, meanwhile if found other solution I will post here.

 

 

@parry2k  I just tried as per your proposal but I got the below error message and it stops me to change the cross filter direction to single. How can I fix this error?

Thanks for your help!

 

image.png

 

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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