Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Number format in Class() function

Hello,

I'm using the Class() function in an Calculated Dimension as this:

= Class([Ventas 2011 (Millones)], 50000, 'Ventas')

Now, this is how the Bar Chart looks like:

Class Bar Chart.png

And I want the numbers in the dimension to have the number format, i.e. 50.000 <= Ventas < 100.000.

How can I do that?

Thanks!

Best regards!

7 Replies
CELAMBARASAN
Partner - Champion
Partner - Champion

Use Num(ClassExpression,'###.###')

Example

= Num(Class([Ventas 2011 (Millones)], 50000, 'Ventas'),'###.###')

Anonymous
Not applicable
Author

Ok, when I use the sentence = Num(Class([Ventas 2011 (Millones)], 50000, 'Ventas'),'###.###') I have this result:

50.000, and the classes are gone...

How can I do that without sacrifying the classes???

CELAMBARASAN
Partner - Champion
Partner - Champion

Its not possible directly

You need to do some work around

like

=Num(SubField(Class([Ventas 2011 (Millones)], 50000, 'Ventas'),' <= Ventas < ', 1),'###.###') & ' <= Ventas < ' & Num(SubField(Class([Ventas 2011 (Millones)], 50000, 'Ventas'),' <= Ventas < ',2),'###.###')

Hope this helps

whiteline
Master II
Master II

Hi.

Class() returns dual value that has numeric value and text representation.

Num() converts text representation, so this type expressions: Num(Class()) works well without any additional 'work'.

It seems that you use implicit aggregation and that's a problem when you add another function.

Choose the aggregation  explicitly:

=aggr(Num(Class([Ventas 2011 (Millones)], 50000)), [Ventas 2011 (Millones)])

swuehl
MVP
MVP

Class() returns dual value that has numeric value and text representation.

Num() converts text representation, so this type expressions: Num(Class()) works well without any additional 'work'.

Right, class() returns a dual, but the numeric value will only hold the (AFAIR) lower limit of the interval that class() is creating. So, applying num() will only format that lower limit and replace the text value (which holds the full interval as text) with the formatted numeric value (like Juan observed also).

If you want to keep both limits of the interval in the text representation, I believe you need to use some kind of text manipulation, something along the lines Celambarasan suggested.

Would be nice if QV would just apply the standard number format by default.

whiteline
Master II
Master II

50.000, and the classes are gone...

Thanks, Stefan, I've missunderstood.

I thought all classes rows are gone, not just '<= Ventas < N' from labels...

In that case don't see the need to use class() with string parsing functions:

=aggr(Num(Div([Ventas 2011 (Millones)],50000)*50000, '###.###') &  ' <= Ventas < ' &

         Num(Div([Ventas 2011 (Millones)],50000+1)*50000, '###.###'), [Ventas 2011 (Millones)])

swuehl
MVP
MVP

You're right, if you need to change the string format that class() will return, it's probably better not to use class() at all.

And if the classification is only based on field value (no aggregation, not depending on selection state), like in the discussed chart, I think it's even better to calculate the classification in the script.

You can then use one of the classification methods discussed here:

http://community.qlik.com/message/240288#240288

Regards,

Stefan