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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

help with DAX measure

Hi All,

 

I am building a PowerBi report, sourcing data from a PowerBI dataset. Hence there are no options available to change the data model. Below sample dataset records the exams taken by a list of students. The requirement is to only list the students that have only taken 'maths' exam. In this dataset, only student 4 should come in the output. Is there a way to achieve this in DAX, rather than changing the data model?

 

Student NoExam
1maths
1english
1science
2science
3english
3maths
4maths

 

Regards,

Murali

1 ACCEPTED SOLUTION
daxer-almighty
Solution Sage
Solution Sage

Of course there is. You have to write a measure that will return 1 for the rows you want to keep and 0 for the others. Then use the measure as the filter in the Filter Pane of your visual. Very simple. Here's something to get you started:

 

// Assuming that your table as shown is 
// T, you can have a measure:

[Taken Only Maths?] =
var __studentNumber = selectedvalue( T[Student No] )
var __exams =
    FILTER(
        ALL( T ),
        T[Student No] = __studentNumber
    )
var __takenMath =
    0 < countrows(
        filter(
            __exams,
            T[Exam] = "maths"
        )
    )
var __notTakenNonMaths =
    0 = countrows(
        filter(
            __exams,
            T[Exam] <> "maths"
        )
    )    
return
    int( __takenMath && __notTakenNonMaths )

View solution in original post

1 REPLY 1
daxer-almighty
Solution Sage
Solution Sage

Of course there is. You have to write a measure that will return 1 for the rows you want to keep and 0 for the others. Then use the measure as the filter in the Filter Pane of your visual. Very simple. Here's something to get you started:

 

// Assuming that your table as shown is 
// T, you can have a measure:

[Taken Only Maths?] =
var __studentNumber = selectedvalue( T[Student No] )
var __exams =
    FILTER(
        ALL( T ),
        T[Student No] = __studentNumber
    )
var __takenMath =
    0 < countrows(
        filter(
            __exams,
            T[Exam] = "maths"
        )
    )
var __notTakenNonMaths =
    0 = countrows(
        filter(
            __exams,
            T[Exam] <> "maths"
        )
    )    
return
    int( __takenMath && __notTakenNonMaths )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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