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
MickyG
Frequent Visitor

DISTINCTCOUNT() of name without a record that CONTAINS()

I want to get the distinct count of the StudentName that DOES NOT contain a record with the keyword "Withdrawn". So the DAX formula result for the data below should have a  single count for each student's name except for Richard Gear because he has the keyword "Withdrawn" in one of his records. Also, there is a calendar table. If the formula can include filters by date so I can use a slider. The records should be within the MIN() and MAX() of the Calendar Table.

DATA:

MickyG_0-1675264276999.png

 

RESULT:

MickyG_1-1675264621668.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @MickyG ,

 

Here are the steps you can follow:

1. Create measure.

Flag =
var _min=MINX(ALLSELECTED('Date'),[Date])
var _max=MAXX(ALLSELECTED('Date'),[Date])
return
IF(
CONTAINSSTRING(MAX('Table'[Result]),"Withdrawn")=FALSE()&&
MAX('Table'[Exam Date])>=_min&&MAX('Table'[Exam Date])<=_max,1,0)
Measure =
CALCULATE(DISTINCTCOUNT('Table'[StudentName]),
    FILTER(ALLSELECTED('Table'),
    'Table'[StudentName]=MAX('Table'[StudentName])))

2. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1675390874595.png

3. Result:

vyangliumsft_1-1675390874600.png

 

Best Regards,

Liu Yang

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

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Create a calculated column formula

Test = search("Withdrawn",Data[Results],1,0)

To your visual, drag Name and this measure

Measure = calculate(countrows(Data),Data[Test]=0)

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi  @MickyG ,

 

Here are the steps you can follow:

1. Create measure.

Flag =
var _min=MINX(ALLSELECTED('Date'),[Date])
var _max=MAXX(ALLSELECTED('Date'),[Date])
return
IF(
CONTAINSSTRING(MAX('Table'[Result]),"Withdrawn")=FALSE()&&
MAX('Table'[Exam Date])>=_min&&MAX('Table'[Exam Date])<=_max,1,0)
Measure =
CALCULATE(DISTINCTCOUNT('Table'[StudentName]),
    FILTER(ALLSELECTED('Table'),
    'Table'[StudentName]=MAX('Table'[StudentName])))

2. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1675390874595.png

3. Result:

vyangliumsft_1-1675390874600.png

 

Best Regards,

Liu Yang

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

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.