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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
manideep547
Helper III
Helper III

Average For String Data Type

Hi ALL,
I have a column Amount but it is in varchar datatype but here my problem is I have to calculate the average of the Amount 
table A (Id, Amount)
1          10.00

2           20.00

3            50.00 

1            15.00

2           25.00

3          55.00
Average of all customer = Average(Table A[Amount]) but here the Amount is in varchar data type and I am using SQL Server as a direct query result =(10+20+50+15+25+55)/3=58.33

2 ACCEPTED SOLUTIONS

In a direct query, you have to use another option cast to a number. By *1 or by bring number from DB

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

v-alq-msft
Community Support
Community Support

Hi, @manideep547 

 

Based on your description, you can use Value function to convert from text to number when it is calculated. Therefore, you may create a measure as follows.

 

AverageMeasure = 
DIVIDE(
    SUMX(
        'Table A',
        VALUE('Table A'[Amount])
    ),
    DISTINCTCOUNT('Table A'[Id])
)

 

 

Result:

a2.png

 

Best Regards

Allan

 

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-alq-msft
Community Support
Community Support

Hi, @manideep547 

 

If you take the answer of someone, please mark it as the solution to help the other members who have same problems find it more quickly. If not, let me know and I'll try to help you further. Thanks.

 

Best Regards

Allan

v-alq-msft
Community Support
Community Support

Hi, @manideep547 

 

Based on your description, you can use Value function to convert from text to number when it is calculated. Therefore, you may create a measure as follows.

 

AverageMeasure = 
DIVIDE(
    SUMX(
        'Table A',
        VALUE('Table A'[Amount])
    ),
    DISTINCTCOUNT('Table A'[Id])
)

 

 

Result:

a2.png

 

Best Regards

Allan

 

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

 

 

amitchandak
Super User
Super User

Why you can not change the data type in power BI.

 

Try Averagex(table, Amount*1.0), If it error, then filter the table for those items

like

Averagex(filter(table,not(isblank(amount)), Amount*1.0),

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

 

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak  For direct query can we change the data type? 
can you please suggest me if how can change the data type for a column in direct query mode?
thank you.

In a direct query, you have to use another option cast to a number. By *1 or by bring number from DB

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak Is there is an option to change the mode from import to direct query?

Hi, @manideep547 

 

It is unsupported to change from import to DirectQuery mode. While it is possible to switch a model from DirectQuery mode to use import mode, all the necessary data must be imported. It's also not possible to switch back, primarily because of the set of features not supported in DirectQuery mode.

 

For further information, you may refer to the following link.

https://docs.microsoft.com/en-us/power-bi/desktop-directquery-about

 

Best Regards

Allan

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.