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
rachaellearns
Frequent Visitor

Slicing Using Multiple Columns Using AND Logic

Hello,

 

I have a dataset that looks something like this:

student_idstatusgenderrace_ethnicityspecial_edellgifted
1on_trackFBlack or African American001
2off_trackMWhite100
3on_track MWhite001
4on_trackFHispanic/Latino011
5off_trackFHispanic/Latino000
6on_trackMBlack or African American001
7on_trackFWhite001
8off_trackMAsian001
9off_trackFWhite100

 

 

I want to show the percentage of students in each demographic group who are "on track" and "off track" in one visualization, with a slicer that enables users to select a demographic attribute to view. I want users to be able to select multiple attributes that combine using 'and' logic. For example, if users simply want to see how Asian students are performing, they can select 'Asian' from the slicer, and the % of off track and on track Asian students will appear. If users would like to see how Asian males are performing specifically, users can select 'Male' and 'Asian', and the graph will adjust.

 

 

  (Right now, I have a separate visualization (Clustered column chart) for each demographic column (one visualization for race, one for gender, one for english language learners, ect.) The axis is the demographic column, the legend is the status column, and the value is the following measure:

 

Measure = DISTINCTCOUNT('table'[student_id])/CALCULATE(DISTINCTCOUNT('table'[student_id]), ALL('table'[status]))

 

So, for example, in the gender table, Male and Female appear on the axis. In the male section, there are two columns, one representing the percentage of on track male students (50%), and one representing the percentage of off track male students(50%). The same is setup appears for female students. )

 

I have tried unpivoting the gender - gifted columns and using the resulting single column to slice the data, but this does not give me the desired result.  I have also tried creating a slicer table, but that did not work. 

 

Please help... any guidance on this would b greatly appreciated. 

 

 

 

2 REPLIES 2
parry2k
Super User
Super User

@rachaellearns try this measure

 

Measure = DISTINCTCOUNT('table'[student_id])/
CALCULATE(DISTINCTCOUNT('table'[student_id]), ALLSELECTED('table'))

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



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.

Hi @parry2k, thank you for your response. This works in a way, but it does not work exactly how I would like it to work.  

 

I would like a slicer that uses and logic - so if Asian & Male is selected in the slicer, student number 8, who is Asian and male, populates (along with any other Asian males in the dataset). Right now, if I select Asian and male, all students who are either Asian or male are included. 

The slicer is set up as follows:

1. I combined the gender, race, special ed, ell, and gifted columns into one column and called that column "alldemo". 

2. I created a slicer table like this:

SlicerTable = DISTINCT(
    UNION(
        SELECTCOLUMNS(
            'table', 
            "Selection", 'table'[gender], 
            "All Demographics", 'table'[alldemo]),
        SELECTCOLUMNS(
            'table',
            "Selection", 'table'[race_ethnicity],
            "All Demographics", 'table'[alldemo]),
        SELECTCOLUMNS(
            'table',
            "Selection", 'table'[gifted],
            "All Demographics", 'table'[alldemo]),
        SELECTCOLUMNS(
            'table',
            "Selection", 'table'[ell],
            "All Demographics", 'table'[alldemo]),
        SELECTCOLUMNS(
            'table',
            "Selection", 'table'[special_ed],
            "All Demographics", 'table'[alldemo]
)))

 I then linked the "All Demographics" column in 'SlicerTable' to the alldemo column in 'table'

 

Next, I create the slicer using the "Selection" column in 'SlicerTable'. The "Selection" column is also the axis on the viz.

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.