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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calcuating average for a numerical + text mixed column

Hi,

 

I have a sales column in which some rows have numbers but some have random strings as well.

I want to eliminate the strings and only calcualte average for the numbers.

 

I have written this calculation but it doesnt work

 

calculate  sales = CALCULATE(AVERAGE('Table'[Sales]),filter('Table',ISNUMBER('Table'[Sales])=TRUE))

 

 

Sales column:

kapillehar_0-1611831765486.png

 

 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

HI @Anonymous 

Download this sample PBIX file with data and measure

You can create this measure

 

Sales_Avg = AVERAGEX(FILTER('Sales', IFERROR(VALUE('Sales'[Sales]) >= 0,0)), VALUE('Sales'[Sales]))

 

 

avg-sal.png

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

6 REPLIES 6
Tahreem24
Super User
Super User

@Anonymous ,
If you follow the said steps so you'll get your expected output:

Capture.PNG

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard
PhilipTreacy
Super User
Super User

HI @Anonymous 

Download this sample PBIX file with data and measure

You can create this measure

 

Sales_Avg = AVERAGEX(FILTER('Sales', IFERROR(VALUE('Sales'[Sales]) >= 0,0)), VALUE('Sales'[Sales]))

 

 

avg-sal.png

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

didn't work for me.

I have a column with the same problem (mixed number and text), plus I also want to filter it by a certain id, either with or without the id doesn't work!

 

Satisfaccion global = AVERAGEX(FILTER('Survey User Input Line', 'Survey User Input Line'[question_id.id]=571 && IFERROR(VALUE('Survey User Input Line'[suggested_answer_id.name]) >= 0,0)), VALUE('Survey User Input Line'[suggested_answer_id.name]))​

 


OR

 

 

Satisfaccion global = AVERAGEX(FILTER('Survey User Input Line', IFERROR(VALUE('Survey User Input Line'[suggested_answer_id.name]) >= 0,0)), VALUE('Survey User Input Line'[suggested_answer_id.name]))​

 


the error:


MdxScript(Model) (13, 96) Calculation error in measure 'Survey User Input Line'[Satisfaccion global]: DAX comparison operations do not support comparing values of type Text with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.

 

 

Anonymous
Not applicable

Hi Phil,

 

This works but im confused what your iferror and value dax is doing.

Can you explain

Hi @Anonymous 

The IFERROR( VALUE() ) is a parameter for FILTER.

What is happening is that for each value in the 'Sales'[Sales] column, try to convert it to a number using VALUE().

If that causes an error then return a 0, otherwise return the actual number.

If an error is generated the filter looks like FILTER('Sales', 0) which returns nothing, and as an error will only be generated when you try to convert a non-numeric text value to a number - this filters out any letters/words.

The final result of FILTER is a column (it's actually a table, but anyway) that consists of the values

1

2

3

4

5

6

7

8

 

AVERAGEX goes through each row in that column adding up the values resulting from converting the text numbers to actual numbers using VALUE('Sales'[Sales]) and then working out the average.  

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Tahreem24
Super User
Super User

@Anonymous ,

DO the below steps:

Step 1: Create a column like below DAX:

Sepearte Num =
VAR IsNum = IF(TableName[Mixed Column] in {"0","1","2","3","4","5","6","7","8","9"},1,0)
VAR num = IF(IsNum=1,(TableName[Mixed Column]))
RETURN num
 
Step 2: Make the above column to Whole number from format option
 
Step 3: Create a measure like below:
AVERAGE(TableName[Sepearte Num])
Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.