Using DataSet value in numeric formula errors with "can't be coerced into BigDecimal"

I uploaded a DataSet with basically two columns:

  • id string
  • value numeric. E.g. 12.34, 56.12, 98.13

I then created a schema

  • MyId = Dataset Column “id”, random
  • referenceValue = DataSet Column “value”
  • randomValue = Normal Distribution mean 1, fx = this * referenceValue

This gives “error: FormattedValue can’t be coerced into BigDecimal”

I also tried using randomValue = Normal Distribution, fx = this * from_dataset(“MyDataset”, “varlue”, id: field(“MyId”)

This gives the error about “could not access blank value”, which I couldn’t workaround

It seems like the Dataset code is failing to recognize that the “value” column in my dataset are numeric values, and I don’t see a function to convert a string to a numeric value.

There’s a bit of a trick to this that I could improve. Numeric values in datasets are returned as a Mockaroo internal type called FormattedValue. You can access the underlying BigDecimal value using the “raw” method. For example:

this * referenceValue.raw

1 Like

This works, thank you. It should be documented in https://mockaroo.com/help/formulas

ASIDE: other recommendations for the help page:

  1. maybe separate string and numeric functions. I was just looking for numeric functions but the list is a little messy.
  2. suggest adding an example to round() that you can use negative decimal places. round(a,-3) worked great when I wanted to round to 1000s
  3. is there an abs() function? I suppose I could use “if a<0 then …” but a function would be nice

thanks!

(this * -1 if this < 0) or (this * 1 if this > 0) works equivalent to the unsupported abs() function