cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rush
Helper IV
Helper IV

How to Sum then Average based on certain conditions in a DAX Measure?

I have a table called Billing Info which has columns:

  • Year-Month (Text)
  • UserName (Text)
  • GP (Decimal Number)
  • BillingType (Text) - which needs to be filtered down to "Fixed Monthly Rate"

I would like to work out the Average GP for Fixed Monthly Rate per Year-Month.

 

I would need to sum the total GP per UserName per Year-Month then work out the average over that.

 

Sample Data


Example:

sample gp data.PNG

 

 

 

 

1 ACCEPTED SOLUTION
v-qiuyu-msft
Community Support
Community Support

Hi @rush,

 

From the error message, column [Gauteng] is TEXT data type. And you have specify the aggregation (eg: SUM) for this column in the measure while this aggregation doesn't support TEXT values. So please check the [Gauteng], see if it can be convert to number.

 

By the way, you can upload your .pbix file to OneDrive or Dropbox and share the link here.

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-qiuyu-msft
Community Support
Community Support

Hi @rush,

 

Measure1 = IF(MAX('Table1'[BillingType])="Fixed Monthly Rate", CALCULATE(AVERAGE(Table1[GP]),FILTER(ALL('Table1'),'Table1'[BillingType]="Fixed Monthly Rate" )),BLANK())

 

Measure 2 = CALCULATE(AVERAGE(Table1[GP]),ALLEXCEPT(Table1,'Table1'[UserName]))

 

a3.PNG

 

If above DAX doesn't meet your requirement, please share screenshots about the desired results for our analysis.

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you @v-qiuyu-msft

 

It does not bring back my desired results.

 

Please see below of the final result:

Data Preview Result.PNG

 

 

 

 

 

 

 

 

Table desired results:

Desired results table.PNG

 

 

 

 

v-qiuyu-msft
Community Support
Community Support

Hi @rush,

 

As your sample data you provided doesn't contain StaffRegion while the desired results have it, you can try the below DAX:

 

Measure = CALCULATE(AVERAGE(Table1[GP]),FILTER(ALL(Table1),'Table1'[Year-Month]=MAX('Table1'[Year-Month])),VALUES(Table1[StaffRegion]))

 

If it doesn't work, please share corresponding sample data. If possible, please share the .pbix with us.

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-qiuyu-msft, thanks but it gives me an error on the text to type number.

 

I will update the sample file as I cannot share the pbix file.

 

It throws back an error:

Error.PNG

 

 

 

 

v-qiuyu-msft
Community Support
Community Support

Hi @rush,

 

From the error message, column [Gauteng] is TEXT data type. And you have specify the aggregation (eg: SUM) for this column in the measure while this aggregation doesn't support TEXT values. So please check the [Gauteng], see if it can be convert to number.

 

By the way, you can upload your .pbix file to OneDrive or Dropbox and share the link here.

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

@v-qiuyu-msft Thanks, I managed to resolve the issue.

anupampandey
Helper III
Helper III

@rush,

 

Could you share some sample data please?

 

Thanks,

Anupam 

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Urdu Hindi D365 Bootcamp 768x460.png

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors