How to cast a number as string with formatting

I have a measure sum field and an example value could be $1.45M, but sometimes we need it to say "N/A". 

My idea was to convert rev to a string and it works, but I lose all the formatting 

I then tried keeping rev as a number and then create a new measure called rev_string and then convert it to string, but I still lose the formatting.  

is there anyway to keep the numeric format in a string?

measure: rev_string {
group_label: "KPI Values"
label: "rev_string"
type: string
sql:
{% if xxx._parameter_value == 'Stay' %}
"N/A"
{% else %}
cast(${rev} as string)
{% endif %};;

}

measure: rev {
group_label: "KPI Values"
label: "rev"
type: sum
sql:
{% if xx._parameter_value == 'Stay' %}
null
{% else %}
coalesce(${rev},0)
{% endif %};;
value_format_name: decimal_0
html: @{number_format} ;;

 

Solved Solved
0 1 42
1 ACCEPTED SOLUTION

Try adding value format this way in the first measure you mentioned.
value_format: "##0"   -- whole number with no decimal values.
It should resolve your formatting.

If it solves your problem, do mark it as a solution so that others can implement same.
Thanks.

View solution in original post

1 REPLY 1

Try adding value format this way in the first measure you mentioned.
value_format: "##0"   -- whole number with no decimal values.
It should resolve your formatting.

If it solves your problem, do mark it as a solution so that others can implement same.
Thanks.

Top Labels in this Space