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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Unable to change data type in calculated column

Hi Everyone,

 

I am adding an addtional column in my table in data window and performing an if statement.

 

Statement : Column=IF(Table[Distance]=0,"-",100-(100*Table[Reversing Upon Vehicle Start Up]/Table[COUNT]))

 

I also want to add more column with different formulae like 

Cornering = IF(Table[Distance]=0,"=",MAX(100-((Table[Count]*1609.34)/Table[Distance]),0))
 

 

I am unable to get "-" when I am running the statement reason is my output would be a numeric number so I want to change my data type as Any so that I can perform the analysis.

 

Note: I don't want to change the type as String becuse I want to pefrom some mathematical calulcations also want to add other columns consisting Max,Min conditions. Is there any if I can add a custom column in query editor and can apply some If, Max, Min condition in column and change data type as "Any"

 

Please see the below table and expected column output

DistanceCountColumn
06-
08-
013-
015-
011-
170.142857
1130.076923
21141.5
16121.333333
25161.5625
25151.666667
32171.882353
480.5
3147.75
39201.95
3984.875
551
33132.538462
13200.65
20111.818182
4058
24201.2

 

DistanceCountColumn
06-
08-
013-
015-
011-
170.142857
1130.076923
21141.5
16121.333333
25161.5625
25151.666667
32171.882353
480.5
3147.75
39201.95
3984.875
551
33132.538462
13200.65
20111.818182
4058
24201.2

 

Kindly help

 

Regards

Uphar Tandon

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Why would string prevent you from doing your mathematical calculations?  Store as string, and then when you do want to do your calculation (and you are confident the stored string is actually a number and not just a "-") you convert the value programmatically to number.

 

Or, you know, you could use BLANK() instead of "-", and not have these issues at all.

View solution in original post

3 REPLIES 3
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

Apart from what Ibendin has mentioned, the formula for MAX is wlso incorrect. 

MAX takes in Column as an input while you have given mathematical expression in the function.

 

Cornering =

var a = 'Table'[Count]*1609.34
var b = DIVIDE(a, 'Table'[Distance])
var c = 100 - b

RETURN
 
IF('Table'[Distance]=0,"=", CONVERT(c,STRING))
 
 
You can either convert the column into a string and then convert it back into integer when you want to do the MIN,MAX calculation.
 
Regards,
Harsh Nathani
 
 
 
lbendlin
Super User
Super User

Why would string prevent you from doing your mathematical calculations?  Store as string, and then when you do want to do your calculation (and you are confident the stored string is actually a number and not just a "-") you convert the value programmatically to number.

 

Or, you know, you could use BLANK() instead of "-", and not have these issues at all.

Anonymous
Not applicable

Thanks for the suggestion. Its working 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors