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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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

 

 

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.