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

Trying to total an Attendance Value based on a 1 or 0 flag in another table

Student

Student NumberStudentSchoolSchool idCaucasionAfricanIndigenous
654651654Jim JonesABC Elementary150001
845484654Jen JimsABC Elementary150001
984654984Kim StevesABC Elementary150010

 

School

SchoolSchool NumberDistrict
ABC Elementary150North

 

Attendance

DistrictSchoolStudent NumberAbsences
NorthABC Elementary654651654

6

NorthABC Elementary845484654

5

NorthABC Elementary984654984

3

 

I have 3 tables like above, related like this:

 

Active Schools 1  <-----> Many   Active Students on School ID

 

Active Students 1 < ---> 1 Attendance on Student ID

This is one to one because when the data was pulled from our Student info it was aggregated per student by late, Absent, Religious holiday etc to make pulling data easier.

 

So my questions is how can I take a total sum on the attendance grouped by Demographic.

 

The result should be 

African - 3

Indigenous - 11

Caucasian - 0

 

I feel like this requires more advanced Dax expressions that i am not familiar with but please any solution i would love!

1 ACCEPTED SOLUTION

The DAX is always easier when you have the correct table structure. Can a student have a 1 for more than one demographic?  If not, I suggest you use Power Query to add a single new column that contains the word relating to each student.  Then with the mode l you have, the DAX will be a simple sum. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

View solution in original post

5 REPLIES 5

The DAX is always easier when you have the correct table structure. Can a student have a 1 for more than one demographic?  If not, I suggest you use Power Query to add a single new column that contains the word relating to each student.  Then with the mode l you have, the DAX will be a simple sum. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Yes unfortunately some students can Identify as more than one demographic where a 1 will be populated in the corresponding column.

Then what is the total to be if a student has 1 in a second column?  Regardless, I would then change the model. This is how I would do it

create a unique student table without the demographic columns

create a second table called demographics. Unpivot the demographic columns and remove the zeros. 
join the first table to the second 1:many

turn in BI directional filtering (assuming performance is not impacted). Less than 1m students should be fine. 
use the attribute column from the demographic table - it should just work, not withstanding my opening question



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

The behaviour would be if a student has 2 demographics they would be counted for the total in each one independent of each other. Because of the way they identify demographics this is how it has to be, we cannot assume they identify as one more than the other. I hope this makes sense.

Basically I am looking to do a sum attendance if African from table 2 is equal to a 1 and the same for each other demographic.

Maybe this is not possible?

If you configure the solution as I have described it will work as you have suggested. The only issue is the grand total will not add up, but you can just turn that off


* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

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.