Forum Discussion

harshadrokade's avatar
harshadrokade
Post Partisan
4 years ago
Solved

Average calculation

I Have below data.

I want to generate a column that will give me difference between below values for each Class-

  1. Average score of specific Class ( Like for CLass 1, average of Student A,B,C)
  2. Average score of all the Class (Average score of all the Class will be calculated based on the Average score generated for each Class & not base on avarage of all the students) (i.e. average of all class average generated as per above 1st item)

Student data table-

ClassStudentScore
1A2
1B3
1C4
2D1
2E2
3F5
3G3
3H5
3I2
4J3
4K1
4L3

 

  • bcdobbs's avatar
    bcdobbs
    4 years ago

    That's really odd. 

    can you create a new test measure same as above but without the difference.

     

    Test Measure
    
    VAR AverageAllClasses = 
    	CALCULATE (
    		[Average by Class],
    		REMOVEFILTERS()
    	)
    		
    RETURN AverageAllClasses

      Drop that into matrix as well and send results. 

  • bcdobbs's avatar
    bcdobbs
    4 years ago

    I've updated my demo file with the code I sent and it's working.

     

    Do you want to have a look and see if you can spot what the difference is?

     

    Same link for demo 

11 Replies

  • bcdobbs's avatar
    bcdobbs
    Community Champion

    I think you just need a measure like this:

    Average by Class = 
        AVERAGEX (
            VALUES ( Result[Class] ),
            CALCULATE ( AVERAGE ( Result[Score] ) )
        )


    VALUES ( Result[Class] ) creates a list of classes.
    AVERAGEX then iterates over this list and calculates an AVERAGE for each.
    The CALCULATE is needed as it forces a context transition so you only get an average for the current class.

     

    You can then use the measure in a matrix visual which you can see in this demo.

    • harshadrokade's avatar
      harshadrokade
      Post Partisan

      bcdobbs Thanks sir. The card is showing 

       

      Actually I am trying to add a column which will provide me the difference between average score by class & average of that class. I need a measure for the same.

       

      Can you pls help me with the same which will provide me difference bewteen Average score of specific Class  & verage score by Class

      • bcdobbs's avatar
        bcdobbs
        Community Champion
        Avg Difference = 
        
        VAR AverageAllClasses = 
        	CALCULATE (
        		[Average by Class],
        		REMOVEFILTERS()
        	)
        		
        RETURN [Average by Class] - AverageAllClasses


        Try this.

        Add a matrix visual with classes on the rows and drop this into the values.