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
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
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.