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
ClaireBear
Helper I
Helper I

Dax to calculate all subjects by completed subjects

Hi, 

 

I am trying to work out the Training Status % based off all subjects vs completed subjects. 

For one customer, the total subjects to be completed are 4 (account id 1) and another 49 (account id 2) for example

My calculations are:

 

Total Subjects = DISTINCTCOUNT('Dimension Subject'[SubjectID])
Completed Subjects = CALCULATE(Distinctcount('DimensionLearning'[SubjectID]),'DimensionLearning'[issubjectcompleted]=True)
Training Status % = [Completed Subjects]/[Total Subjects]
 
Below is an example for Account ID 1. Would you be able to assist with a dax to fix table 1 and get a result of table 2?
 
The issue is with the Subjects All calculation
 
Table 1  Incorrect Incorrect
ClientAccount idZoneSubjects AllCompleted SubjectsTraining Status %
CLA1Pizza33100%
CLA1Cake King33100%
CLA1Fish3133%
CLA1Milk Shake2150%
CLA1Coffee4375%
CLA1Pies3267%
CLA1Burgers3267%

 

 

Table 2  Correct Correct
ClientAccount idZoneSubjects AllCompleted SubjectsTraining Status %
CLA1Pizza4375%
CLA1Cake King4375%
CLA1Fish4125%
CLA1Milk Shake4125%
CLA1Coffee4375%
CLA1Pies4250%
CLA1Burgers4250%
      

Thanks

 
 
1 ACCEPTED SOLUTION
ClaireBear
Helper I
Helper I

Hi, thank you so much. I managed to add a calculated column

 

No of Subjects= CALCULATE(DISTINCTCOUNT('Dimension Subject'[SubjectID]),FILTER('Dimension Subject','Dimension Subject'[accountID]=EARLIER('Dimension Subject'[accountID])))
 
I then created a measure using the max function and it seemed to work.
 
Total Subjects= max('Dimension Subject'[No of Subjects])

View solution in original post

2 REPLIES 2
ClaireBear
Helper I
Helper I

Hi, thank you so much. I managed to add a calculated column

 

No of Subjects= CALCULATE(DISTINCTCOUNT('Dimension Subject'[SubjectID]),FILTER('Dimension Subject','Dimension Subject'[accountID]=EARLIER('Dimension Subject'[accountID])))
 
I then created a measure using the max function and it seemed to work.
 
Total Subjects= max('Dimension Subject'[No of Subjects])
SteveHailey
Solution Specialist
Solution Specialist

Hi @ClaireBear. Try this for your total subjects measure:

Total Subjects =
CALCULATE (
    DISTINCTCOUNT ( 'Dimension Subject'[SubjectID] ),
    ALL ( 'Dimension Subject' )
)

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.