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
acs
Regular Visitor

COUNTIF in DAX going haywire?

Hey folks. Have been bashing my brain on a problem and tried multiple help posts' solutions to no avail.

I've have a fairly chunky set of data from a quiz (600k+ rows).

 

Each question has a [questionID] so we know which question is which.


Each user that takes the test has a [userID].

If they get a question right [answer-score] column is 1. If they get a question wrong [answer-score] column is 0.

 

I want to get:

 

a) a total of all questions answered (easy enough - a COUNT of all [answer-score]

b) a total of all questions answered wrong

c) a total of all questions answered right

 

It's the last two that are foxing me.

 

So far I have: created a new 'measure' thus:

Wrong = CALCULATE

(COUNT('public test_records'[answer_score]),'public test_records'[answer_score]=0)

 

That didn't work. I got, randomly... "33" as the answer. From 600k+ rows of data? Unlikely... even plain wrong (I counted more than that myself). Smiley Very Happy


So I tried: 


Right = CALCULATE(COUNT('test_records'[answer_score]),
FILTER('production test_records','production test_records'[answer_score]=1))

That gave me "50". Nice round number but again... "what the?"

Close to gnawing my keyboard. Grateful for any help. What am I missing? Oh for Excel and COUNTIF! Smiley LOL

2 REPLIES 2
Greg_Deckler
Super User
Super User

Sample data would assist tremendously. Are you sure there is no other context filters going on that would make the measure end up with those numbers?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
jthomson
Solution Sage
Solution Sage

Don't think I've ever used count, I'd just use countrows here. Make a measure Answered similar to your first one for your all questions bit, then for each of your right/wrong things, make a measure Right= calculate([Answered],[answer-score]=1) and similar for wrong answers

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.