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
Anonymous
Not applicable

Filtering dynamically with slicer selections

Hello,

 

This is maybe a bit of a tricky one. I have a dataset which counts unique people aggregated by demographic and purchasing variables:

Age groupSexApplesOrangePearsPeachesKiwiN
10-19Female1010032
20-29Male0001046
40-49Female111007
20-29Female1010118
30-39Male0110133

(e.g. 32 females aged 10-19 purchased Apples and Pears).

 

I'd like to create a slicer where users can select multiple values for the listed fruits (Apples, Oranges, Pears, Peaches and Kiwi), then count the total number of unique people (N) who purchase at least one of the selected fruits. (e.g. rows 1,4,5 and 6 all purchased apples and/or kiwis, so if a user selects Apples and Kiwis, I will sum(n) on all those rows). 

 

Most guides I've found have suggested unpivoting the data table, but if I do this it will cause aggregate groups that have more than one of the selected fruits to be duplicated in the rows, which will make my sums of [n] inaccurate. 

 

Some other work arounds I've considered or attempted are:

  • Import the data unaggregated and unpivoted. I'd prefer to avoid this as the table will be tens of millions of rows, and is slightly less private/secure. 
  • Dynamically write a sum if statement in dax which uses the slicer selections (from what I can tell, this isn't possible, particularly if the slicer is set as multiselect). 
  • Create a calculated column which draws on a measure that concatonates the slicer selections and uses CONTAINSSTRING() to generate a flag I can use for filtering (I thought this worked, but it appears that the calculated column doesn't update dynamically when the slicer selections change). 

I'm at a loss what to attempt next, and hoping someone has a good idea!

 

 

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

I would still unpivot my table but make sure that each row is counted only once. To do that, I'd craete an index column in the query editor prior to unpivoting as a unique reference to the original set of rows and then use the measure below

Unique Count = 
SUMX ( SUMMARIZE ( 'Table', 'Table'[Index], 'Table'[N] ), [N] )

danextian_0-1703224738896.png

Please see attached pbix for the details










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

4 REPLIES 4
danextian
Super User
Super User

Hi @Anonymous ,

 

As always, please post a sample data that can be copy-pasted to Excel as a table (not an image).










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Hi @danextian, apologies, I have changed the format of the table so that you should now be able to copy and paste it

 

Hi @Anonymous ,

 

I would still unpivot my table but make sure that each row is counted only once. To do that, I'd craete an index column in the query editor prior to unpivoting as a unique reference to the original set of rows and then use the measure below

Unique Count = 
SUMX ( SUMMARIZE ( 'Table', 'Table'[Index], 'Table'[N] ), [N] )

danextian_0-1703224738896.png

Please see attached pbix for the details










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Thanks @danextian , I think this solves my problem!

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.