<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>article KPIs formatting by using class() in Member Articles</title>
    <link>https://community.qlik.com/t5/Member-Articles/KPIs-formatting-by-using-class/ta-p/1496325</link>
    <description>&lt;P&gt;If you build BI frontends you probably meet a challenge to visualize measures not knowing if they are in thousands or millions. Beacuse of that some posts about formatting these kinds of measures (above all because of KPIs) has been written already. I decided to spend some minutes on my own to find the solution and here it is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Problem we want to solve:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;We do not know if the measure will be in hundreds, thousands or millions&lt;/LI&gt;
&lt;LI&gt;Final measure should consists of maximum 3 characters before and 2 after the decimal separator&lt;/LI&gt;
&lt;LI&gt;Final measure should contain unit of measure in text form&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wonder only about the solution feel free to scroll to the end &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" border="0" /&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let’s try to figure it out in logic steps (in case of this example we use simple sum(Value) as a measure):&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1. We intuitively class numbers into units, thousands and millions. The difference between thousand and one is 3 more numbers. The difference between million and thousand is 3 more numbers, too. It is obvious that the crucial aspect is the length of a measure – in multiples of 3:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/200446_Pic1.png" border="0" alt="Pic1.png" width="245" height="97" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Since before the delimiter we want to have only up to 3 numbers values that consists of up to 3 characters (0-999) should stay unchanged, thousands (4-6 characters) should be divided by 1 000 and millions (7-9 characters) by 1 000 000. It seems as a work for class() function. However, if we use it just in simple way class(len(sum(Value)),3) the result is:&lt;/P&gt;
&lt;P&gt;&lt;IMG class="jive-image image-2" src="https://community.qlik.com/legacyfs/online/200456_Pic2.png" border="0" alt="Pic2.png" width="349" height="114" /&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3. We can see that value 136 (which we do not want to change) is in the same class as value 9 582 which should be divided. This leads us to a small modification of the class function class(len(sum(Value))-1,3):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG class="jive-image image-3" src="https://community.qlik.com/legacyfs/online/200457_Pic3.png" border="0" alt="Pic3.png" width="387" height="100" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;4. &lt;/SPAN&gt;&lt;SPAN&gt;Class() function is dual so except for the text presentation 3 &amp;lt;= x &amp;lt; 6 we can refer to the left interval’s border by using another function num(class()):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG class="image-4 jive-image" src="https://community.qlik.com/legacyfs/online/200458_Pic4.png" border="0" alt="Pic4.png" width="483" height="109" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;5. &lt;/SPAN&gt;&lt;SPAN&gt;The factor we want to use for dividing of thousands is of course 1 000 = pow(10,3) and for millions 1 000 000 = pow(10,6). Values smaller than one thousand do not need to be modified but we can divide them by 1 which is nothing else then pow(10,0). In general we have the function:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG style="height: 112px; width: 620px;" class="image-5 jive-image" src="https://community.qlik.com/legacyfs/online/200459_Pic5.png" border="0" alt="Pic5.png" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;6. &lt;/SPAN&gt;&lt;SPAN&gt;Let’s look at decimal places. As we focus on details we know that if the value has not been divided (and is the whole number) then we do not have to write anything after decimal separator (this depends on your data - if you have the raw data in decimals then you need to probably use only general function round(*,'0.01')):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG style="height: 108px; width: 620px;" class="jive-image image-6" src="https://community.qlik.com/legacyfs/online/200460_Pic6.png" border="0" alt="Pic6.png" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;7. &lt;/SPAN&gt;&lt;SPAN&gt;By using the same logic as we define the power of 10 that should be used for dividing the value we can assign the text of corresponding unit to the measure: &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG style="height: 104px; width: 723.711px;" class="jive-image image-7" src="https://community.qlik.com/legacyfs/online/200461_Pic7.png" border="0" alt="Pic7.png" width="724" height="105" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;8. When we add together everything we have done in previous steps our expression will look like this:&lt;/P&gt;
&lt;P&gt;&lt;IMG style="height: 164.499px; width: 409px;" class="image-8 jive-image" src="https://community.qlik.com/legacyfs/online/200464_Pic8.png" border="0" alt="Pic8.png" width="409" height="165" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... it makes sense - qlik makes it ... &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/wink.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maria&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jun 2022 08:36:56 GMT</pubDate>
    <dc:creator>JaMajka1</dc:creator>
    <dc:date>2022-06-28T08:36:56Z</dc:date>
    <item>
      <title>KPIs formatting by using class()</title>
      <link>https://community.qlik.com/t5/Member-Articles/KPIs-formatting-by-using-class/ta-p/1496325</link>
      <description>&lt;P&gt;If you build BI frontends you probably meet a challenge to visualize measures not knowing if they are in thousands or millions. Beacuse of that some posts about formatting these kinds of measures (above all because of KPIs) has been written already. I decided to spend some minutes on my own to find the solution and here it is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Problem we want to solve:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;We do not know if the measure will be in hundreds, thousands or millions&lt;/LI&gt;
&lt;LI&gt;Final measure should consists of maximum 3 characters before and 2 after the decimal separator&lt;/LI&gt;
&lt;LI&gt;Final measure should contain unit of measure in text form&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wonder only about the solution feel free to scroll to the end &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" border="0" /&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let’s try to figure it out in logic steps (in case of this example we use simple sum(Value) as a measure):&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1. We intuitively class numbers into units, thousands and millions. The difference between thousand and one is 3 more numbers. The difference between million and thousand is 3 more numbers, too. It is obvious that the crucial aspect is the length of a measure – in multiples of 3:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/200446_Pic1.png" border="0" alt="Pic1.png" width="245" height="97" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Since before the delimiter we want to have only up to 3 numbers values that consists of up to 3 characters (0-999) should stay unchanged, thousands (4-6 characters) should be divided by 1 000 and millions (7-9 characters) by 1 000 000. It seems as a work for class() function. However, if we use it just in simple way class(len(sum(Value)),3) the result is:&lt;/P&gt;
&lt;P&gt;&lt;IMG class="jive-image image-2" src="https://community.qlik.com/legacyfs/online/200456_Pic2.png" border="0" alt="Pic2.png" width="349" height="114" /&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3. We can see that value 136 (which we do not want to change) is in the same class as value 9 582 which should be divided. This leads us to a small modification of the class function class(len(sum(Value))-1,3):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG class="jive-image image-3" src="https://community.qlik.com/legacyfs/online/200457_Pic3.png" border="0" alt="Pic3.png" width="387" height="100" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;4. &lt;/SPAN&gt;&lt;SPAN&gt;Class() function is dual so except for the text presentation 3 &amp;lt;= x &amp;lt; 6 we can refer to the left interval’s border by using another function num(class()):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG class="image-4 jive-image" src="https://community.qlik.com/legacyfs/online/200458_Pic4.png" border="0" alt="Pic4.png" width="483" height="109" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;5. &lt;/SPAN&gt;&lt;SPAN&gt;The factor we want to use for dividing of thousands is of course 1 000 = pow(10,3) and for millions 1 000 000 = pow(10,6). Values smaller than one thousand do not need to be modified but we can divide them by 1 which is nothing else then pow(10,0). In general we have the function:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG style="height: 112px; width: 620px;" class="image-5 jive-image" src="https://community.qlik.com/legacyfs/online/200459_Pic5.png" border="0" alt="Pic5.png" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;6. &lt;/SPAN&gt;&lt;SPAN&gt;Let’s look at decimal places. As we focus on details we know that if the value has not been divided (and is the whole number) then we do not have to write anything after decimal separator (this depends on your data - if you have the raw data in decimals then you need to probably use only general function round(*,'0.01')):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG style="height: 108px; width: 620px;" class="jive-image image-6" src="https://community.qlik.com/legacyfs/online/200460_Pic6.png" border="0" alt="Pic6.png" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;7. &lt;/SPAN&gt;&lt;SPAN&gt;By using the same logic as we define the power of 10 that should be used for dividing the value we can assign the text of corresponding unit to the measure: &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG style="height: 104px; width: 723.711px;" class="jive-image image-7" src="https://community.qlik.com/legacyfs/online/200461_Pic7.png" border="0" alt="Pic7.png" width="724" height="105" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;8. When we add together everything we have done in previous steps our expression will look like this:&lt;/P&gt;
&lt;P&gt;&lt;IMG style="height: 164.499px; width: 409px;" class="image-8 jive-image" src="https://community.qlik.com/legacyfs/online/200464_Pic8.png" border="0" alt="Pic8.png" width="409" height="165" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... it makes sense - qlik makes it ... &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/wink.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maria&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 08:36:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/KPIs-formatting-by-using-class/ta-p/1496325</guid>
      <dc:creator>JaMajka1</dc:creator>
      <dc:date>2022-06-28T08:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: KPIs formatting by using class()</title>
      <link>https://community.qlik.com/t5/Member-Articles/KPIs-formatting-by-using-class/tac-p/1496326#M309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice !&lt;/P&gt;&lt;P&gt;BTW have you seen the new system variable that allows to control numerical abbreviations for KPIs ? It's a useful feature for customization, e.g. :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;SET &lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;NumericalAbbreviation = '3:k;6:M;9:B;12:T';&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2018 23:26:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/KPIs-formatting-by-using-class/tac-p/1496326#M309</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-10T23:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: KPIs formatting by using class()</title>
      <link>https://community.qlik.com/t5/Member-Articles/KPIs-formatting-by-using-class/tac-p/1496327#M310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes sure and it looks great! Maybe there is almost the same algorithm as mine behind it &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/grin.png" /&gt;. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 May 2018 06:18:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/KPIs-formatting-by-using-class/tac-p/1496327#M310</guid>
      <dc:creator>JaMajka1</dc:creator>
      <dc:date>2018-05-21T06:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: KPIs formatting by using class()</title>
      <link>https://community.qlik.com/t5/Member-Articles/KPIs-formatting-by-using-class/tac-p/1496328#M311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Heyy, check out the following discussion I tried something similar and that works with charts too &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/message/1409678"&gt;can we change sorting rule based on expression?&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 May 2018 06:31:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/KPIs-formatting-by-using-class/tac-p/1496328#M311</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-22T06:31:29Z</dc:date>
    </item>
  </channel>
</rss>

