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
slhangen
Helper II
Helper II

Need count with multiple filters

I have created and Append table and need to get some calculations from it.

Table is called Append1 and looks like following:

TITLESTUDENT LAST NAMESTUDENT FIRST NAMEDESIGNATIONCOURSETEACHERSEMESTER GRADESEMESTER
999999ADAMSHENRY ADV PHY EDMAHRINGASEM 1
999999ADAMSHENRY DRAWING IBEINTUMFSEM 1
999999ADAMSHENRY DRIVER ED CLASSSTEPHENSBSEM 1
999999ADAMSHENRY INTR TECH & ENGRICEFSEM 1
999999ADAMSHENRY KEYBOARD FORMATQUILTYASEM 1
999999ADAMSHENRYCOREENGLISH IIPAINTERASEM 1
999999ADAMSHENRYESSAGEOMETRYRENOBSEM 1
999999ADAMSHENRYESSAPHYS SCIENCEFOGLIANOFSEM 1
222222ADAMSJOHN APPLIED MANUFACRICEASEM 1
222222ADAMSJOHN ARMY JROTC IIIWilliamsDSEM 1
222222ADAMSJOHN CAREER PLANHUBERTFSEM 1
222222ADAMSJOHNCOREAM GOVERNMENTPHILLIPSDSEM 1
222222ADAMSJOHNCOREAP ENGLISH LITRHOADESDSEM 1
222222ADAMSJOHNCOREECONOMICSQUILTYFSEM 2
333333AGUILERACHRISTINA ARMY JROTC IIIWilliamsCSEM 1
333333AGUILERACHRISTINA DRIVER ED CLASSSTEPHENSFSEM 1
333333AGUILERACHRISTINA ELL TUTORIALHINRICHSENFSEM 1
333333AGUILERACHRISTINA ESL IIBAILEYCSEM 1
333333AGUILERACHRISTINA SPAN HRT SPK IIHINRICHSENFSEM 1
333333AGUILERACHRISTINACOREUS HISTORYBAILEYCSEM 1
333333AGUILERACHRISTINAESSABIOLOGYCMCKENZIEBSEM 1
333333AGUILERACHRISTINAESSAGEOMETRYSZECHOWYCZFSEM 1

 

Need some DAX give me the following:

TITLESTUDENT LAST NAMESTUDENT FIRST NAMECOURSE FAILURESSEMESTER GRADESEMESTER
999999ADAMSHENRY3FSEM 1

 

Was thinking I could replicate this for SEM 2 in another table/measure.

 

Thx, Community!

1 ACCEPTED SOLUTION
edhans
Super User
Super User

Take a look at the following @slhangen - just one measure I think is all you need:

edhans_0-1610046625365.png

Course Failures = 
COUNTX(
    FILTER(
        'Table',
        'Table'[SEMESTER GRADE] = "F"
    ),
    'Table'[SEMESTER GRADE]
)

Simply add the fields I have added to a Table visual, then add the Course Failures measure I created. It will calculate the correct numbers per semester.

If that is not what you need, could you be more specific in the output you require and the logic to get there?



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

10 REPLIES 10
edhans
Super User
Super User

Glad I was able to help @slhangen - hope your project moves forward smoothly.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
edhans
Super User
Super User

Take a look at the following @slhangen - just one measure I think is all you need:

edhans_0-1610046625365.png

Course Failures = 
COUNTX(
    FILTER(
        'Table',
        'Table'[SEMESTER GRADE] = "F"
    ),
    'Table'[SEMESTER GRADE]
)

Simply add the fields I have added to a Table visual, then add the Course Failures measure I created. It will calculate the correct numbers per semester.

If that is not what you need, could you be more specific in the output you require and the logic to get there?



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

This is amazing Ed, but I really need the following:

 

TITLE      STUDENT LAST NAME      STUDENT FIRST NAME     COURSE FAILURES- SEM 1     COURSE FAILURES- SEM 2

 

Can you help with this?  I would be forever on your debt, lol.

Sure, that will require two measures:

 

Course Failures Semester 1 = 
COUNTX(
    FILTER(
        'Table',
        'Table'[SEMESTER GRADE] = "F"
            && 'Table'[SEMESTER] = "SEM 1"
    ),
    'Table'[SEMESTER GRADE]
)

 

and 

 

Course Failures Semester 2 = 
COUNTX(
    FILTER(
        'Table',
        'Table'[SEMESTER GRADE] = "F"
            && 'Table'[SEMESTER] = "SEM 2"
    ),
    'Table'[SEMESTER GRADE]
)

 

Then I got rid of the Semester field in the visual and added both of these measures, and I get this:

edhans_0-1610056742569.png

Alternatively, you can keep my original measure and use a MATRIX visual instead:

edhans_1-1610056881069.png

It has these fields:

edhans_2-1610056909986.png

You need to do a few things to the matrix to make it work and look like I have it:

  • Turn off stepped layout
  • Turn off row subtotals
  • Drill all the way down on the matrix using the single-to-double down arrow when you hover over the matrix.
    • edhans_3-1610056991801.png

       

  • I like the matrix solution better because it is 1 measure and the semesters would dynamically expand (summer summester for example) without having to write a 3rd semester measure.

But that is the cool thing about Power BI @slhangen - different ways to do the same thing. Take your pick!

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

I keep getting an error with this code. 
Table is called Append1 (See screenshot).

 

 

Course Failures Semester 1 =
COUNTX(
FILTER(
'Append1',
'Append1'[SEMESTER GRADE]="F"
&& Append1[SEMESTER]="SEM 1"
),
'Append1'[SEMESTER GRADE]
)
 

 


Am I typing everything correct?

 

THx so much for your time.

 

There was no screenshot. What is the error? The only other suggestion I have with the info I have is to use this:

Course Failures Semester 1 =
COUNTAX(
    FILTER(
        'Append1',
        'Append1'[SEMESTER GRADE] = "F"
            && Append1[SEMESTER] = "SEM 1"
    ),
    'Append1'[SEMESTER GRADE]
)

COUNTAX can operate on a boolean data type, but COUNTX won't return an error, it just won't count the true/false values. But if you have text in the semester grade field, it shouldn't matter.

 

Can you confirm that you have set the field data types correctly? [Semester Grade] and [Semester] should be text. In Power Query (The transform button in the home ribbon), ensure the icon in the upper left is ABC, not ABC/123.

edhans_0-1610065382901.png

If it is ABC123, click it and select Text. Do that for every column. No columns brought into Power BI should he set to ABC123.


Otherwise, you will need to share actual files via Dropbox or OneDrive that I can take a look at.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thx so much for your help on this.   Below is a link for some sample data,

https://www.dropbox.com/scl/fi/2nrenbotacx7d72q1rt6w/1-8-SAMPLE-DATA.xlsx?dl=0&rlkey=dqd7sl6ng56zb41...

 

Thx again, you are a life saver!

Capture.JPG

@slhangen you don't create a table. You create a measure. Then you create a table visual. See my PBIX file here



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thx so miuch, got it working.  Appreciate all of your time and effort.  Thx again!!!

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.

Top Solution Authors