Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
HassanAshas
Helper V
Helper V

ERROR in Bar Graph: DIVIDE scalar expressions have to be Aggregation Functions over CurrentGroup()

Hi, let me first provide a bit of the background of what I am trying to solve, 

 

I have a dataset of employees working on month-to-month basis, 

 

Emp Code MonthAllocationProject Code
1UmairAug-220Bench
1Umair1-Sep0Bench
1UmairOct-22120Bench
1UmairNov-22160Bench
1UmairDec-22168Bench
1UmairAug-22184A
1Umair1-Sep0A
1UmairOct-220A
1UmairNov-220A
1UmairDec-220A
2AveryAug-22184Bench
2Avery1-Sep0Bench
2AveryOct-220Bench
2AveryNov-220Bench
2AveryDec-220Bench
3AryubAug-22184Bench
3Aryub1-Sep168Bench
3AryubOct-22154Bench
3AryubNov-22120Bench
3AryubDec-22166Bench
4FailakAug-2224Bench
4Failak1-Sep0Bench
4FailakOct-22120Bench
4FailakNov-22160Bench
4FailakDec-2288Bench
4FailakAug-22164C
4Failak1-Sep166C
4FailakOct-2240C
4FailakNov-220C
4FailakDec-2288C

 

In this dataset, the "Allocation" column means the Hours Employee has worked in that specific month on that specific project.

 

What I need to do is find the Utilization Efficiency of all the employees. The Utilization efficiency has a simple formula, 

 

 

Utilization Efficiency = Total Hours Worked in a Month / Total Working Days in that Month

 

 

So, that is, If I am talking about August 2022, and for Emp ID: 4

Total Working Hours = 184 (found using NETWORKDAYS)

Emp ID 4 working hours = 164 (on Project C) + 24 (on Project Bench) = 188 Hours

Emp ID 4 Utilization Efficiency = 188 / 184 = 1.02 

 

I have made a DAX that is able to do the above for me. The DAX is as follows, 

 

 

Aggregate_Working_Hours = 

VAR __Working_Hours = NETWORKDAYS(MAX(Competency[Date]), EOMONTH(MAX(Competency[Date]), 0)) * 8

VAR __Table = 
        GROUPBY(
            'Competency',
            Competency[Emp Code],
            "__Allocation",SUMX(CURRENTGROUP(),DIVIDE((Competency[Allocation]), __Working_Hours, 0))
        )
    VAR __Result = SUMX(__Table,[__Allocation])
RETURN
    __Result

 

 

Please note that I have a Single Select on the Months Slicer, and hence this DAX works for and finds the correct results for me. 

 

The logic of the DAX is as follows, 

 

  • Calculate the working hours of the Selected Month in the Slicer
  • Groupby all the records of "one employee" together and calculates its Utilization Efficiency for that month (For this, we first calculate utilization efficiency for each of the employee record for that specific month and then SUM up all the utilization efficiency values)
  • At the end, we sum up all the Utilization Efficiencies of all the employees, to get the aggregate value of the complete dataset. 

 

Now, I need to do one more thing. I need to display the Aggregate Working Hours in a Trend Line or Bar Graph with Months in X-Axis (for this visual, interaction will be turned off with the Months Slicer) 

 

so, what I did is simply used a Trend Line and placed Month on the X-axis and the Measure on the Y-Axis, but it didn't display any result and showed me the following error, 

 

Calculation error in measure 'All Measures'[Aggregate_Working_Hours]: Function 'DIVIDE' scalar expressions have to be Aggregation functions over CurrentGroup(). The expression of each Aggregation has to be either a constant or directly reference the columns in CurrentGroup().

 

I can't figure out what is the problem. On trying to search the internet, I found that I need to use SUMMARIZE function. I tried to implement the same logic with SUMMARIZE but with SUMMARIZE, I unfortunately can't use CURRENTGROUP and hence, I am not able to replicate the same logic with that. Can anyone help me out in this? 

 

Here is the POWER BI File if you would like to download: https://drive.google.com/file/d/16SjSNce8Y-nDBQxoFZLGV9GUs-47sc46/view?usp=sharing

 

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @HassanAshas ,

 

Try the following code:

Aggregate_Working_Hours = 

VAR __Working_Hours = NETWORKDAYS(MAX(Competency[Date]), EOMONTH(MAX(Competency[Date]), 0)) * 8

VAR __Table = 
        SUMMARIZE(
            'Competency',
            Competency[Emp Code],
            "__Allocation",SUMX( Competency,DIVIDE((Competency[Allocation]), __Working_Hours, 0))
        )
    VAR __Result = SUMX(__Table,[__Allocation])
RETURN
    __Result

 

MFelix_0-1676367117286.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @HassanAshas ,

 

Try the following code:

Aggregate_Working_Hours = 

VAR __Working_Hours = NETWORKDAYS(MAX(Competency[Date]), EOMONTH(MAX(Competency[Date]), 0)) * 8

VAR __Table = 
        SUMMARIZE(
            'Competency',
            Competency[Emp Code],
            "__Allocation",SUMX( Competency,DIVIDE((Competency[Allocation]), __Working_Hours, 0))
        )
    VAR __Result = SUMX(__Table,[__Allocation])
RETURN
    __Result

 

MFelix_0-1676367117286.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Oh God! How did I miss that 😐 Sorry for such a bad question. Thanks a lot for pointing out the mistake, greatly appreciate it! 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.