Forum Discussion

pintobean87's avatar
pintobean87
Frequent Visitor
3 years ago

Error while trying to sum and get the average from two calculated columns

Hi all.

 

So I have the following 3 columns in my table: Name, QTR 1, QTR 2. QTR 1 and 2 are calculated columns that I made to get the difference from other columns.

It's important to note that there might be multiple row entries for the same name as shown above.

 

So what I'm trying to do is to get the total average in QTR 1 for each name. For example, for Red under QTR 1, the sum would be 17 and so the result should display the average which is 5.66.  This would repeat in QTR 2, so the average for Red would be 3 there.

 

Finally, the end result should add the two averages together from both columns, so in the case of Red, it would add 5.66 and 3 to return 8.66

 

I wrote the DAX below but keep running into an error that says something about "function groupby scalar expressions have to be aggregation." 

 

Not sure how to figure this out. Any help is appreciated!

 

 

Total Average by Name = AVERAGEX(GROUPBY('Table', 'Table'[Name], "TotalValue", (AVERAGE('Table'[QTR1]) + AVERAGE('Table'[QTR2]))), [TotalValue])

2 Replies

  • pintobean87's avatar
    pintobean87
    Frequent Visitor

    Or is there just an easier way to do the math than what I'm trying to do?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi pintobean87 

    Try the following measure

    Measure = var a=CALCULATE(AVERAGE('Table'[QTR1]),ALLEXCEPT('Table','Table'[Name]))
    var b=CALCULATE(AVERAGE('Table'[QTR2]),ALLEXCEPT('Table','Table'[Name]))
    return a+b

    Output

     

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.