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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
jrmaier
Helper IV
Helper IV

Sum and display columns based on slicer

I work at a high school using a hybrid schedule. Some students in on A days and others in on B days. Some parents want their kids at school everyday (A-S, B-S designations on their record) I need to figure out how many A hybrid and B student kids are in each class to see if we have enough safe room for all in the classroom or if we need to have some students watching the class on Zoom from somewhere else in the building.

 

Trying to have A-H # and B-S # show and sum when A is selected on the Group slicer and the same for B-H# and A-S# when Group B is selected. 

Snag_c021322.png

Currently both A's show up when group A is selected and same for B because I originally created new columns using "Group" & "Attend" 

Snag_c0b0ccd.png

2 ACCEPTED SOLUTIONS

@tex628 Awesome. Thanks for your help! 

View solution in original post

Hi @jrmaier ,

 

You can also create a slicer table:

 

Capture.PNG

 

Then use the following measure in your matrix:

 

 

measure = 
SWITCH (
    SELECTEDVALUE ( 'Table2'[slicer] ),
    "A",
        IF (
            HASONEVALUE ( 'Data'[Code] ),
            IF (
                MAX ( 'Data'[Code] ) IN { "A-H", "B-S" },
                CALCULATE (
                    COUNT ( 'Data'[User ID] ),
                    FILTER (
                        ALLEXCEPT ( 'Data', 'Data'[Room Number], 'Data'[Course Title], 'Data'[Block] ),
                        'Data'[Code] = MAX ( 'Data'[Code] )
                    )
                ),
                BLANK ()
            ),
            CALCULATE (
                COUNT ( 'Data'[User ID] ),
                FILTER (
                    ALLEXCEPT ( 'Data', 'Data'[Room Number], 'Data'[Course Title], 'Data'[Block] ),
                    'Data'[Code] IN { "A-H", "B-S" }
                )
            )
        ),
    "B",
        IF (
            HASONEVALUE ( 'Data'[Code] ),
            IF (
                MAX ( 'Data'[Code] ) IN { "A-S", "B-H" },
                CALCULATE (
                    COUNT ( 'Data'[User ID] ),
                    FILTER (
                        ALLEXCEPT ( 'Data', 'Data'[Room Number], 'Data'[Course Title], 'Data'[Block] ),
                        'Data'[Code] = MAX ( 'Data'[Code] )
                    )
                ),
                BLANK ()
            ),
            CALCULATE (
                COUNT ( 'Data'[User ID] ),
                FILTER (
                    ALLEXCEPT ( 'Data', 'Data'[Room Number], 'Data'[Course Title], 'Data'[Block]),
                    'Data'[Code] IN { "A-S", "B-H" }
                )
            )
        ),
    "C",
        IF (
            MAX ( 'Data'[Code] ) = "C-R",
            CALCULATE (
                COUNT ( 'Data'[User ID] ),
                FILTER (
                    ALLEXCEPT ( 'Data', 'Data'[Room Number], 'Data'[Course Title], 'Data'[Block]),
                    'Data'[Code] = MAX ( 'Data'[Code] )
                )
            ),
            BLANK ()
        )

 

 

Capture1.PNG

 

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EcbBOLH1ufxFtl5jNF...

 

Please be kind to accept useful reply as answer ,not your own reply.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

 

View solution in original post

23 REPLIES 23
tex628
Community Champion
Community Champion

The table there is created through the "Enter data" fuctionality, you can edit it directly in power query to match your requirement:

Gif1.gif

Just make sure that the codes in the "Code" column correspond to the correct codes in the main table.

/ J


Connect on LinkedIn

@tex628 Awesome. Thanks for your help! 

Hi @jrmaier ,

 

You can also create a slicer table:

 

Capture.PNG

 

Then use the following measure in your matrix:

 

 

measure = 
SWITCH (
    SELECTEDVALUE ( 'Table2'[slicer] ),
    "A",
        IF (
            HASONEVALUE ( 'Data'[Code] ),
            IF (
                MAX ( 'Data'[Code] ) IN { "A-H", "B-S" },
                CALCULATE (
                    COUNT ( 'Data'[User ID] ),
                    FILTER (
                        ALLEXCEPT ( 'Data', 'Data'[Room Number], 'Data'[Course Title], 'Data'[Block] ),
                        'Data'[Code] = MAX ( 'Data'[Code] )
                    )
                ),
                BLANK ()
            ),
            CALCULATE (
                COUNT ( 'Data'[User ID] ),
                FILTER (
                    ALLEXCEPT ( 'Data', 'Data'[Room Number], 'Data'[Course Title], 'Data'[Block] ),
                    'Data'[Code] IN { "A-H", "B-S" }
                )
            )
        ),
    "B",
        IF (
            HASONEVALUE ( 'Data'[Code] ),
            IF (
                MAX ( 'Data'[Code] ) IN { "A-S", "B-H" },
                CALCULATE (
                    COUNT ( 'Data'[User ID] ),
                    FILTER (
                        ALLEXCEPT ( 'Data', 'Data'[Room Number], 'Data'[Course Title], 'Data'[Block] ),
                        'Data'[Code] = MAX ( 'Data'[Code] )
                    )
                ),
                BLANK ()
            ),
            CALCULATE (
                COUNT ( 'Data'[User ID] ),
                FILTER (
                    ALLEXCEPT ( 'Data', 'Data'[Room Number], 'Data'[Course Title], 'Data'[Block]),
                    'Data'[Code] IN { "A-S", "B-H" }
                )
            )
        ),
    "C",
        IF (
            MAX ( 'Data'[Code] ) = "C-R",
            CALCULATE (
                COUNT ( 'Data'[User ID] ),
                FILTER (
                    ALLEXCEPT ( 'Data', 'Data'[Room Number], 'Data'[Course Title], 'Data'[Block]),
                    'Data'[Code] = MAX ( 'Data'[Code] )
                )
            ),
            BLANK ()
        )

 

 

Capture1.PNG

 

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EcbBOLH1ufxFtl5jNF...

 

Please be kind to accept useful reply as answer ,not your own reply.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors