SUMIF OR - Calculated field in PowerPivot

DonnaEm

New Member
Joined
Nov 25, 2012
Messages
7
I am using this as an exercise to learn powerpivot calculated fields. My question: is there a more efficient way to write the formula below? In Excel I'd join up SUMIFs so that's what I did here but I'm sure there must be a better way. The issue is that some classes have "A+","A",A-" etc so my formula is going to end up very long to cater for all types of pass grade.
Would it be more efficient to just add a Case When field to the SQL script to bring the data into the PowerPivot as Pass/Fail? Many thanks in advance for your advice :)

There are 36 students in the class who each did 3 tests. I've been asked to provide the number who passed each test.

Assessment Distinct Count of Student_ID Students who Passed
Test 1 36 34
Test 2 36 35
Test 3 36 29

The formula to determine how many students passed:

=CALCULATE(
DISTINCTCOUNT('Query 1'[Student_ID])
, FILTER('Query 1','Query 1'[GradeCode]="A")
)
+CALCULATE(
DISTINCTCOUNT('Query 1'[Student_ID])
, FILTER('Query 1','Query 1'[GradeCode]="B")
)
+CALCULATE(
DISTINCTCOUNT('Query 1'[Student_ID])
, FILTER('Query 1','Query 1'[GradeCode]="C")
)
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
One options is to make a measure like this and just add more grade codes as needed.

Students who Passed:=CALCULATE(COUNT('Query 1'[Student_ID]),FILTER('Query 1','Query 1'[GradeCode] = "A" || 'Query 1'[GradeCode] = "A+" || 'Query 1'[GradeCode] = "A-" || 'Query 1'[GradeCode] = "B" ))
 
Upvote 0
Kazlik's formula works, but if you have the option, I would recommend bringing in a calculated flag via the SQL case statement. This keeps things tidy and improves performance in PowerPivot. For example: CASE WHEN GradeCode = 'F' THEN 0 ELSE 1 END AS PassFl.
 
Upvote 0
Expanding on Kazlik's formula, I would simply count the rows of the table expression returned by the FILTER function:
=COUNTROWS(FILTER('Query 1','Query 1'[GradeCode] = "A" || 'Query 1'[GradeCode] = "A+" || 'Query 1'[GradeCode] = "A-" || 'Query 1'[GradeCode] = "B" ))
 
Upvote 0
Thank you very much for your help everyone. I knew there must be a more efficient way. I will probably do as kitjosh suggests and amend my SQL script to bring the data in more tidily in this situation but the other formulas will be useful for another piece of code I'm working on. I'm assuming that || is some kind of separator between the filters. That was the part I was missing. Thanks again - I appreciate the time you took to read my post and comment on it :)
 
Upvote 0

Forum statistics

Threads
1,215,584
Messages
6,125,670
Members
449,248
Latest member
wayneho98

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top