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
duesouth
Helper I
Helper I

Filter by a Measure

I have created a Power BI Dashboard for a UK secondary school.  We have various behaviour events in our MIS, which include when pupils are sent to the Hub (where they have to do their work in silence outside of the class to reduce disruption to others).  I've written a measure in the behaviour table to count the number of times pupils are sent to the Hub (which can be for a few different reasons).  I would like to filter on a card which shows the average grade (from another table) to show the impact of pupils who are in the Hub far more than others.  However, when I add the measure to the card's "Filter on this visual" section, it won't let me do anything (e.g. set the filter to <=1).  A slicer doesn't accept the measure at all.

I found a YouTube video (https://www.youtube.com/watch?v=AZAL-QPn5Zc) on the subject and copied the DAX and clicked the edit interactions, but this hasn't worked.  Full details are below - if anyone can help with a solution, I'd very much appreciate it.

 

Pupil_Data Table

External IDNameFree School MealsSpecial Education Needs
1Pupil OneNN
2Pupil TwoNN
3Pupil ThreeYN
4Pupil FourNK
5Pupil FiveNN
6Pupil SixYK
7Pupil SevenNN
8Pupil EightYN
9Pupil NineNE
10Pupil TenYE

 

Behaviour Table

External IDDateBehaviour Type
105/09/2024B7 The Learning Hub
107/01/2025No Homework
120/09/2024B7 The Learning Hub - 3 Strikes
103/10/2024B1 No PE Kit
207/10/2024B5 Suspension
203/03/2025B7 The Learning Hub - Lates
317/03/2025No Homework
317/03/2025B7 The Learning Hub - 3 Strikes
318/03/2025B7 The Learning Hub
320/03/2025B7 The Learning Hub - Lates
427/03/2025B7 The Learning Hub
402/04/2025B7 The Learning Hub - 3 Strikes
523/04/2025No Homework
620/05/2025B7 The Learning Hub - No PROUD Card
624/09/2024No Homework
612/12/2024No Homework
619/12/2024B7 The Learning Hub - 3 Strikes
630/09/2024No Homework
708/10/2024B7 The Learning Hub - Lates
804/11/2024B7 The Learning Hub - No PROUD Card
818/11/2024No Homework
822/11/2024No Homework
813/12/2024B1 No PE Kit
817/12/2024No Homework
917/12/2024B7 The Learning Hub - Lates
910/01/2025No Homework
916/01/2025No Homework
1021/01/2025B7 The Learning Hub - Lates
1023/01/2025B1 No PE Kit
1005/02/2025No Homework
1010/02/2025B7 The Learning Hub - No PROUD Card
1025/02/2025B5 Suspension
1005/03/2025B7 The Learning Hub - 3 Strikes

 

Measure to calculate times in the Hub is: 

Number in Hub =
// counts the total number of times a pupil is in the Hub
CALCULATE (
    COUNTROWS ( 'Behaviour' ),
    'Behaviour'[Behaviour Type] = "B7 The Learning Hub"
    || 'Behaviour'[Behaviour Type] = "B7 The Learning Hub - 3 strikes"
    || 'Behaviour'[Behaviour Type] = "B7 The Learning Hub - Lates"
    || 'Behaviour'[Behaviour Type] = "B7 The Learning Hub - No PROUD Card"    
)+0
 
Assessment Table
External IDGradeSubject
18English
17Mathematics
19Science
22English
22Mathematics
23Science
35English
36Mathematics
36Science
47English
48Mathematics
47Science
54English
56Mathematics
58Science
62English
63Mathematics
62Science
74English
75Mathematics
74Science
85English
84Mathematics
83Science
96English
98Mathematics
97Science
106English
104Mathematics
107Science

 

 

From the YouTube video I tried:

 

1) Created a table:

Hub Number Filter =
GENERATESERIES(0, [Number in Hub], 1)
 
2) Measure in the Behaviour table:
Hub Measure Filter =
VAR MinValue = MIN('Hub Number Filter'[Value])
VAR MaxValue = MAX('Hub Number Filter'[Value])
VAR CurrentMeasureValue = [Number in Hub]
RETURN
IF(
    CurrentMeasureValue >= MinValue && CurrentMeasureValue <= MaxValue,
    1,
    0
)
 
3) Second measure in the Behaviour table:
 
Hub Slicer Filter =
VAR Virtual =
SUMMARIZE(
    'Behaviour',
    'Behaviour'[External Id],
    "Hub", [Number in Hub]
)
VAR MinValue = MINX(Virtual,[Number in Hub])
VAR MaxValue = MAXX(Virtual,[Number in Hub])
VAR CurrentSlicerValue = SELECTEDVALUE('Hub Number Filter'[Value])
RETURN
IF(
    CurrentSlicerValue >= MinValue && CurrentSlicerValue <= MaxValue,
    1,
    0
)
 
4) Add slicer to the page 'Hub Number Filter'[Value]
 
5) Edit interactions so other slicers on the page interact with the one above (e.g. one for 'Assessment'[Subject]).
 
The slicer in step 4 shows the correct max and min times pupils are in the hub, but it has no impact on cards on the page...
1 ACCEPTED SOLUTION

Hi @duesouth ,

 

Thank you for reaching out to Microsoft Fabric Community.

 

Above error ( The expression contains columns from multiple tables, but only columns from a single table can be used in a True/False expression that is used as a table filter expression.) can be fixed by replacing it with the below measure. Establish the relation ship between Behaviour  and pupil_data using external ID.

 

NumberInHub_Column =
CALCULATE (
    COUNTROWS (
        FILTER (
            RELATEDTABLE ( Behaviour ),
            Behaviour[Behaviour Type] IN {
                "B7 The Learning Hub",
                "B7 The Learning Hub - 3 Strikes",
                "B7 The Learning Hub - Lates",
                "B7 The Learning Hub - No PROUD Card"
            }
        )
    )
)
 
If you have any further questions, please feel free to share them along with a sample output. We're happy to help.
 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Thank you!!

View solution in original post

4 REPLIES 4
DataNinja777
Super User
Super User

Hi @duesouth ,

 

Power BI doesn't allow you to use a measure as a slicer or directly in visual-level filters because measures are context-dependent and recalculated on the fly. To filter the average grade card by how often a pupil has been sent to the Hub, you need a calculated column that counts the number of times each pupil has been to the Hub. This column can then be used in slicers or as a filter on visuals.

You can add the following calculated column to your Pupil_Data table or whichever table you're using as your base for visuals:

NumberInHub_Column =
CALCULATE (
    COUNTROWS ( Behaviour ),
    FILTER (
        Behaviour,
        Behaviour[Behaviour Type] IN {
            "B7 The Learning Hub",
            "B7 The Learning Hub - 3 Strikes",
            "B7 The Learning Hub - Lates",
            "B7 The Learning Hub - No PROUD Card"
        }
    ),
    Behaviour[External ID] = Pupil_Data[External ID]
)

Once this column is created, you can use it as a visual-level filter in your average grade card. For instance, set the filter to only include pupils with NumberInHub_Column >= 5 to evaluate the impact on students with frequent Hub events. Your average grade measure like this:

Average Grade = AVERAGE(Assessment[Grade])

will now respond to the filter and only show the average for students who meet the specified Hub visit threshold. If you want slicer interactivity, you can also create a GENERATESERIES table and use the selected value from that slicer to filter visuals based on this calculated column. This avoids the issues you faced with measures not being accepted in slicers or filters and gives you the control you need.

 

Best regards,

Thanks for the reply.  I've tried to put in the DAX, but it's returning the error:

 

"The expression contains columns from multiple tables, but only columns from a single table can be used in a True/False expression that is used as a table filter expression."

 

The error is under Pupil_Data[External ID]

 

Any ideas?  Thank you!

Hi @duesouth ,

 

Thank you for reaching out to Microsoft Fabric Community.

 

Above error ( The expression contains columns from multiple tables, but only columns from a single table can be used in a True/False expression that is used as a table filter expression.) can be fixed by replacing it with the below measure. Establish the relation ship between Behaviour  and pupil_data using external ID.

 

NumberInHub_Column =
CALCULATE (
    COUNTROWS (
        FILTER (
            RELATEDTABLE ( Behaviour ),
            Behaviour[Behaviour Type] IN {
                "B7 The Learning Hub",
                "B7 The Learning Hub - 3 Strikes",
                "B7 The Learning Hub - Lates",
                "B7 The Learning Hub - No PROUD Card"
            }
        )
    )
)
 
If you have any further questions, please feel free to share them along with a sample output. We're happy to help.
 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Thank you!!

Many thanks for taking the time to help - much appreciated!

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.