Magic ETL

Magic ETL

Domo Idea Exchange - Beast Modes - Abbreviated Summary Number

Greetings! This is another post highlighting a beast mode from my Domo IDEAs conference session. This one covers how to format numbers a number in an abbreviated format.


Problem:

When concatenating a string with a number the resulting value is a string and unable to utilize Domo's built in formatting.


Solution:

This version only needs to check for length in increments of 3 to determine the correct units (Billions, Millions etc). The case statement goes in a descending order because the case statement will enter the condition that evaluates to true first. So every condition below the top one implies that the first condition is false.

  1. -- Author:
  2. -- Created:
  3. -- Last Modified:
  4. -- Description: Since the numbers are being concatenated with a string
  5. -- Default Domo number formatting is no longer possible. This will format the
  6. -- total of the `random_number` field based on how large the number is.
  7. -- ROUND will format the abbreviation to 2 decimal places.
  8. CONCAT(
  9.   'Total: ',
  10.   -- CASE statements will evaluate the first expression it finds to be true and then exists.
  11.   -- No further conditions are evaluated
  12.   -- If >= 10 digits then it's in the billions
  13.   -- It would need to be expanded to 13 for (T)rillions
  14.   CASE WHEN LENGTH(ROUND(SUM(`random_number`), 0)) >= 10 THEN
  15. CONCAT(ROUND(SUM(`random_number`) / 1000000000, 2), 'B')
  16.   -- 7 digits means Millions
  17.   WHEN LENGTH(ROUND(SUM(`random_number`), 0)) >= 7 THEN
  18. CONCAT(ROUND(SUM(`random_number`) / 1000000, 2), 'M')
  19.   -- 4-6 digits = thousands
  20.   WHEN LENGTH(ROUND(SUM(`random_number`), 0)) >= 4 THEN
  21. CONCAT(ROUND(SUM(`random_number`) / 1000, 2), 'K')
  22.   WHEN LENGTH(ROUND(SUM(`random_number`), 0)) <= 3 THEN
  23.   ROUND(SUM(`random_number`), 0)
  24.   WHEN SUM(`random_number`) IS NULL THEN 0
  25.   ELSE ''
  26.   END
  27. )
  28.  

Note:

These beast modes only go to 100 Billion (12 digits). Any number higher would need to expand using the same logic for higher lengths.

**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**

Comments

Welcome!

It looks like you're new here. Members get access to exclusive content, events, rewards, and more. Sign in or register to get started.
Sign In