Search code examples
dashboardqliksense

Dynamic number system in Qlik Sense


My data consists of large numbers, I have a column say - 'amount', while using it in charts(sum of amount in Y axis) it shows something like 1.4G, I want to show them as if is billion then e.g. - 2.8B, or in millions then 80M or if it's in thousands (14,000) then simply- 14k.

I have used - if(sum(amount)/1000000000 > 1, Num(sum(amount)/1000000000, '#,###B'), Num(sum(amount)/1000000, '#,###M')) but it does not show the M or B at the end of the figure and also How to include thousand in the same code.


Solution

  • EDIT: Updated to include the dual() function.

    This worked for me:

    =dual(
    
    if(sum(amount) < 1, Num(sum(amount), '#,##0.00'),
    if(sum(amount) < 1000, Num(sum(amount), '#,##0'),
    if(sum(amount) < 1000000, Num(sum(amount)/1000, '#,##0k'),
    if(sum(amount) < 1000000000, Num(sum(amount)/1000000, '#,##0M'),
    Num(sum(amount)/1000000000, '#,##0B')
    ))))
    
    , sum(amount)
    )
    

    Here are some example outputs using this script to format it:

    =sum(amount) Formatted
    2,526,163,764 3B
    79,342,364 79M
    5,589,255 5M
    947,470 947k
    583 583
    0.6434 0.64

    To get more decimals for any of those, like 2.53B instead of 3B, you can format them like '#,##0.00B' by adding more zeroes at the end.

    Also make sure that the Number Formatting property is set to Auto or Measure expression.