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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
weilai0521
Frequent Visitor

Slicer to change product user

Hi, 

 

I have a sample data like this. And I need to create a slicer to choose different product users. 

 

Sample DataSample Data

I am working on creating a slicer, which can list the types of products and as I select, it can generate histograms of gender, age, etc. 

 

For example, if I select 'Cigarette', I want to show the demographic breakdown of cigarette smokers. If I choose 'Cigarette' AND 'e-vapor', I can see the demographic statistics for people who are smoking and using e-vapor.

 

Capture1.PNG

2 ACCEPTED SOLUTIONS
v-juanli-msft
Community Support
Community Support

Hi @weilai0521 

1. unpivot column in Query editor

5.png

name column"Attribute"->"product"

 

2. add a custom column

6.png

Close&&apply

 

3.create a calculated column

age range =
SWITCH (
    TRUE (),
    [Age] >= 18
        && [Age] <= 24, "18~24",
    [Age] >= 18
        && [Age] <= 24, "18~24",
    [Age] >= 25
        && [Age] <= 34, "25~34",
    [Age] >= 35
        && [Age] <= 44, "35~44",
    [Age] >= 45
        && [Age] <= 54, "45~54",
    [Age] >= 55
        && [Age] <= 64, "55~64",
    [Age] >= 65, "65+"
)

4.create measures

age/each =
CALCULATE (
    DISTINCTCOUNT ( Sheet6[ID] ),
    FILTER (
        ALLSELECTED ( Sheet6 ),
        Sheet6[age range] = MAX ( Sheet6[age range] )
            && Sheet6[number] = 1
    )
)


age/total =
CALCULATE (
    DISTINCTCOUNT ( Sheet6[ID] ),
    FILTER ( ALLSELECTED ( Sheet6 ), Sheet6[number] = 1 )
)


%/age = [age/each]/[age/total]

gender/each =
CALCULATE (
    DISTINCTCOUNT ( Sheet6[ID] ),
    FILTER (
        ALLSELECTED ( Sheet6 ),
        Sheet6[Gender] = MAX ( Sheet6[Gender] )
            && Sheet6[number] = 1
    )
)

gender/total =
CALCULATE (
    DISTINCTCOUNT ( Sheet6[ID] ),
    FILTER ( ALLSELECTED ( Sheet6 ), Sheet6[number] = 1 )
)

%/gender = [gender/each]/[gender/total]

7.png

Best Regards
Maggie

 

Community Support Team _ Maggie Li
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

Thanks for the details! The unpivot function really helps and I get everything worked out well! I did not find the 'Accept as solution' button, I will check back later to see if I can your post as solution.

View solution in original post

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @weilai0521 

1. unpivot column in Query editor

5.png

name column"Attribute"->"product"

 

2. add a custom column

6.png

Close&&apply

 

3.create a calculated column

age range =
SWITCH (
    TRUE (),
    [Age] >= 18
        && [Age] <= 24, "18~24",
    [Age] >= 18
        && [Age] <= 24, "18~24",
    [Age] >= 25
        && [Age] <= 34, "25~34",
    [Age] >= 35
        && [Age] <= 44, "35~44",
    [Age] >= 45
        && [Age] <= 54, "45~54",
    [Age] >= 55
        && [Age] <= 64, "55~64",
    [Age] >= 65, "65+"
)

4.create measures

age/each =
CALCULATE (
    DISTINCTCOUNT ( Sheet6[ID] ),
    FILTER (
        ALLSELECTED ( Sheet6 ),
        Sheet6[age range] = MAX ( Sheet6[age range] )
            && Sheet6[number] = 1
    )
)


age/total =
CALCULATE (
    DISTINCTCOUNT ( Sheet6[ID] ),
    FILTER ( ALLSELECTED ( Sheet6 ), Sheet6[number] = 1 )
)


%/age = [age/each]/[age/total]

gender/each =
CALCULATE (
    DISTINCTCOUNT ( Sheet6[ID] ),
    FILTER (
        ALLSELECTED ( Sheet6 ),
        Sheet6[Gender] = MAX ( Sheet6[Gender] )
            && Sheet6[number] = 1
    )
)

gender/total =
CALCULATE (
    DISTINCTCOUNT ( Sheet6[ID] ),
    FILTER ( ALLSELECTED ( Sheet6 ), Sheet6[number] = 1 )
)

%/gender = [gender/each]/[gender/total]

7.png

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for the details! The unpivot function really helps and I get everything worked out well! I did not find the 'Accept as solution' button, I will check back later to see if I can your post as solution.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 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.