Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Help needed while calculating a percentage in a text object field

Hello,

I'm trying to calculate a percentage in a text object field.

So far, by using the bellow expression I was able to get the result I want, but it gives me the full % value. But what I really need it a round number with no decimals, or max two decimals numbers.

My values are:

CC: 69

Other: 18

Total (CC + Other) = 87

My expression is:

=count(if([Tipo de contacto]='CC',[Tipo de contacto]))/count([Tipo de contacto])*100 & ' %'

Value gotten so far: 79,310344827586 %

I'm looking for an expression that gives me something like: 79% or 79,31% (with only two decimals)print.JPG

Many thanks for your help.

1 Solution

Accepted Solutions
jwjackso
Specialist III
Specialist III

You can use the Num function to format the number, below should give you 2 decimal places

Num(count(if([Tipo de contacto]='CC',[Tipo de contacto]))/count([Tipo de contacto])*100,'##0.##')


or

no decimal places

Num(count(if([Tipo de contacto]='CC',[Tipo de contacto]))/count([Tipo de contacto])*100,'##0')


https://help.qlik.com/en-US/qlikview/November2017/Subsystems/Client/Content/Scripting/FormattingFunc...

View solution in original post

3 Replies
jwjackso
Specialist III
Specialist III

You can use the Num function to format the number, below should give you 2 decimal places

Num(count(if([Tipo de contacto]='CC',[Tipo de contacto]))/count([Tipo de contacto])*100,'##0.##')


or

no decimal places

Num(count(if([Tipo de contacto]='CC',[Tipo de contacto]))/count([Tipo de contacto])*100,'##0')


https://help.qlik.com/en-US/qlikview/November2017/Subsystems/Client/Content/Scripting/FormattingFunc...

Anonymous
Not applicable
Author

It is correct, it works:

=Num(count(if([Tipo de contacto]='CC',[Tipo de contacto]))/count([Tipo de contacto])*100,'##0,##')& ' %'

This gives the result I want. Many thanks!

sunny_talwar

Also, suggest you to look into set analysis rather than using if statement

=Num(Count({<[Tipo de contacto] = {'CC'}>} [Tipo de contacto])/Count([Tipo de contacto]), '#0.0%')

or this if you want it to be 0 when CC is not selected in Tipo de contacto

=Num(Count({<[Tipo de contacto] *= {'CC'}>} [Tipo de contacto])/Count([Tipo de contacto]), '#0.0%')