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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
roosechua
Frequent Visitor

Excluding filtered records from calculations

Hi All,

 

I would just like to ask for some assistance on a scenario that I am currently working on. I have been thinking how to do this, but somehow, the solution is really out of my depth, so any hint will be appreciated.

 

I am including here some sample tables, but it does simulate the challenge I am facing.

 

My sample PBIX file.

 

There are 3 tables originally:

Table 1: Sections_Questions - This table contains the different sections and the question IDs for each section.

SectionQuestion ID
AA.1
AA.2
AA.3
BB.1
BB.2
BB.3
CC.1
CC.2
CC.3

 

Table 2: Student_Scope - This table contains the student ID and what sections should be under their scope.

Student IDScope
S001A,B,C
S002A,C
S003B,C

 

Table 3: Student_Results - This table contains the Student ID, Question IDs and the student grades for each answered question.

Student IDQuestion IDGrade
S001A.180
S001A.284
S001A.390
S001B.184
S001B.287
S001B.383
S001C.189
S001C.290
S001C.382
S002A.187
S002A.284
S002A.385
S002B.189
S002C.191
S002C.289
S002C.384
S003B.178
S003B.279
S003B.382
S003C.179
S003C.280
S003C.381
S003A.390

 

My sample's data model:

PBIX data model.jpg

 

Students are supposed to answer only those questions that are within their scope, e.g. Student 001 answers all questions under sections A, B and C, while Student 002 should answer only questions under sections A and C, etc. However, they might have answered also some questions that are under a section that was not within their scope, so they have a grade for that question, but those questions should be considered as invalid.

 

When I do my calculations now in Power BI, these invalid questions answered by students that outside of their scope are still showing and affecting the overall output of my computations (I just used an average in the sample PBIX file to show this, but in my real world scenario, I use different measures for this). 

 

My question now is: Without manually using a slicer, or deleting those invalid records in my source files (as there might be hundreds of them), is there any way that I can exclude these invalid questions from being processed at all by my measures? I tried to think how to do this in DAX, but before I do further experimenting, can this be possible to do using DAX at all?

 

Thanks in advance for any advice!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @roosechua,

Here is the measure formula that I directly use DAX expression to extract the corresponding items and store them in a variable to use it as the condition in grade calculations, you can try it if helps:

formula =
VAR scoreList =
    CALCULATE (
        CONCATENATEX ( VALUES ( Student_Scope[Scope] ), [Scope], "," ),
        FILTER (
            ALLSELECTED ( Student_Scope ),
            [Student ID] IN VALUES ( Student_Results[Student ID] )
        )
    )
VAR questList =
    CALCULATETABLE (
        VALUES ( Sections_Questions[Question ID] ),
        FILTER (
            ALLSELECTED ( Sections_Questions ),
            SEARCH ( [Section], scoreList, 1, -1 ) > 0
        )
    )
RETURN
    CALCULATE (
        SUM ( Student_Results[Grade] ),
        FILTER ( ALLSELECTED ( Student_Results ), [Question ID] IN questList ),
        VALUES ( Student_Results[Student ID] )
    )

1.png

Regards,

Xiaoxin Sheng

View solution in original post

1 REPLY 1
Anonymous
Not applicable

HI @roosechua,

Here is the measure formula that I directly use DAX expression to extract the corresponding items and store them in a variable to use it as the condition in grade calculations, you can try it if helps:

formula =
VAR scoreList =
    CALCULATE (
        CONCATENATEX ( VALUES ( Student_Scope[Scope] ), [Scope], "," ),
        FILTER (
            ALLSELECTED ( Student_Scope ),
            [Student ID] IN VALUES ( Student_Results[Student ID] )
        )
    )
VAR questList =
    CALCULATETABLE (
        VALUES ( Sections_Questions[Question ID] ),
        FILTER (
            ALLSELECTED ( Sections_Questions ),
            SEARCH ( [Section], scoreList, 1, -1 ) > 0
        )
    )
RETURN
    CALCULATE (
        SUM ( Student_Results[Grade] ),
        FILTER ( ALLSELECTED ( Student_Results ), [Question ID] IN questList ),
        VALUES ( Student_Results[Student ID] )
    )

1.png

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.