Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Conditional expression number formatting

Hi everyone,

My chart has a conditional expression, that is really two different expressions. The expression used depends on setting a variable elsewhere. It looks something like this:

=if(vExpression='Total Spending',num(sum(Amounts),'$#,###,###'),

if(vExpression='Inventory',sum(Inventory),

))

I have enabled Values on Data Points, and I want the values to be formatted as $ for sum(Amounts), and as number for sum(Inventory). As you can see, I have tried to set the formatting in the expression, and I have set Number Format Settings in the Number tab to 'Expression Default', but this has not worked. Does anyone know of a solution?

Thanks

10 Replies
maxgro
MVP
MVP

maybe

=if('$(vExpression)'=......

Not applicable
Author

Didn't work!

ecolomer
Master II
Master II

Can you try this:

= if($(vExpression)= ...

Not applicable
Author

Didn't work, chart changes to 'No data to display'

maxgro
MVP
MVP

if possible, post a small example of your Qlik doc

Anonymous
Not applicable
Author

A bit of a guess but how about converting the output to text, something like this :

=if(vExpression='Total Spending',text(num(sum(Amounts),'$#,###,###'))

if(vExpression='Inventory',text(sum(Inventory)),

))

Anonymous
Not applicable
Author

Hi,


Crete a variable using below exression


vTest=sum(if($(vExpression)='Total Spending',Amounts,

if($(vExpression)='Inventory',Inventory)))


then use thebelow condition in you calculaiton


=if($(vExpression)='Total Spending',num($(vTest),'$#,###,###')

if($(vExpression)='Inventory',$(vTest)

))


Hope this helps. Pleas check for any missing braces.


BR,

chinna

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

Your expression looks OK, except that the variable may need to be enclosed in quotes and a $ expansion (depending on how the variable is defined), and you need to make sure that the format on the Number tab is set to 'Expression Default'. Otherwise the setting in the Number tab overrides the format in your expression.

Then you may need to explicitly format the second sum (eg  num(sum(Inventory), '# ##0')  )

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Thank you all for your responses.

Unfortunately, both Bill and Chinna's solutions resulted in 'No Data to Display'. And thank you Jonathan, I made sure that "expression default" was selected.

I will try to post a scrambled copy of my QVW soon. In the meantime, thank you all for your helpful responses.