Forum Discussion
stella_moon
6 years agoFrequent Visitor
Expressions that yield variant data-type cannot be used to define calculated columns.
Hello, I have tried to look in the community for the answer. Few issues with the exact error can be found. However, I cannot fix mine. Appreciate that any one can look at my formula. Posit...
- 6 years ago
Hi stella_moon ,
Based on the error message, it is caused by the different data types in column. I think you are trying to use both number value and text value (the value with sign) in one calculate column. So power bi can't auto analysis data type of it.
Maybe you could try like this:
Positive Recovery = IF ( 'Table'[Category] = "Income", "-" & 'Table'[value], 'Table'[value] )Or you could try the function of FORMAT to convert values to text value.
Pre-Defined Numeric Formats for the FORMAT function
If you want to change all the values to number, you need to split the sign in Power Query firstly.
- And create a new column.
= Table.AddColumn(#"Changed Type1", "Custom", each if [value.1] = null then [value.2] else [value.1])
- Then remove other columns.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8sxLzs9NVdJRMjQwUIrViVZyBLK1DA1MwRwnkISRMZjtrADimAFVxQIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Category = _t, value = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"value", type text}}), #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "value", Splitter.SplitTextByDelimiter("*", QuoteStyle.Csv), {"value.1", "value.2"}), #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"value.1", Int64.Type}, {"value.2", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each if [value.1] = null then [value.2] else [value.1]), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"value.1", "value.2"}) in #"Removed Columns"For more details, please see the attachment.
amitchandak
Super User
6 years agostella_moon Try like
Positive Recovery = If ([Category] = "Income", -1*[value],[value])