Trying to calculate percentages for a group values

I am trying to calculate a percentage for each "Bucket".
Less than 0 days past due
1 to 15 days past due
16 to 30 days past due
31 to 60 days past due
I have each calculation and the formula works for each "Bucket" but I cant get them all in one beast mode calculation. Here are my formulas:
Sum(Case
WHEN `DaysPastDue`<= 0 THEN `TotalDue` else 0 end)/sum(`TotalDue`)
Sum(CASE
WHEN `DaysPastDue`>= 1 AND `DaysPastDue`<= 15 THEN `TotalDue` else 0 end)/sum(`TotalDue`)
Sum(Case
WHEN `DaysPastDue`>= 16 AND `DaysPastDue`<= 30 THEN `TotalDue` else 0 end)/sum(`TotalDue`)
sum(case
WHEN `DaysPastDue`>= 31 AND `DaysPastDue`<= 60 THEN `TotalDue` else 0 end)/sum(`TotalDue`)
Sum(case
WHEN `DaysPastDue`>= 61 THEN `TotalDue`else 0 end)/ sum(`TotalDue`)
How do I get them all under one calculation?
Please advise.
Best Answer
-
I'm going to assume this for a table card in my explanation, but you should be able to modify this fairly easily.
Also, youre `TotalDue` field, I'm assuming this needs to be a constant value of all of the item due. If it's not you'll need to calculate that ahead of time and then have it repeat through your dataset, let's call the new column AllDue. This will allow you to return MAX(`AllDue`) at any point in the following calculations and reference all items due (not just a subset, which is what will happen going forward).
So the first part is to identify the "Buckets". This could be the first column of the table:
- CASE WHEN `DaysPastDue` <= 0 THEN 'Less than 0 days past due'
WHEN `DaysPastDue` >= 1 AND `DaysPastDue` <= 15 THEN '1 to 15 days past due'
WHEN `DaysPastDue` >= 16 AND `DaysPastDue` <= 30 THEN '16 to 30 days past due'
WHEN `DaysPastDue` >= 31 AND `DaysPastDue` <= 60 THEN '31 to 60 days past due'
END
You can then follow the same pattern when creating your percentage calculation:
- SUM(CASE WHEN `DaysPastDue` <= 0 THEN `TotalDue`
WHEN `DaysPastDue` >= 1 AND `DaysPastDue` <= 15 THEN `TotalDue`
WHEN `DaysPastDue` >= 16 AND `DaysPastDue` <= 30 THEN `TotalDue`
WHEN `DaysPastDue` >= 31 AND `DaysPastDue` <= 60 THEN `TotalDue`
END)
/
MAX(`AllDue`)
That paired with the buckets beastmode will give you your values and series that you can use.
Let me know if you have any questions on this,
Valiant
**Please mark "Accept as Solution" if this post solves your problem
**Say "Thanks" by clicking the "heart" in the post that helped you.1 - CASE WHEN `DaysPastDue` <= 0 THEN 'Less than 0 days past due'
Answers
-
I'm going to assume this for a table card in my explanation, but you should be able to modify this fairly easily.
Also, youre `TotalDue` field, I'm assuming this needs to be a constant value of all of the item due. If it's not you'll need to calculate that ahead of time and then have it repeat through your dataset, let's call the new column AllDue. This will allow you to return MAX(`AllDue`) at any point in the following calculations and reference all items due (not just a subset, which is what will happen going forward).
So the first part is to identify the "Buckets". This could be the first column of the table:
- CASE WHEN `DaysPastDue` <= 0 THEN 'Less than 0 days past due'
WHEN `DaysPastDue` >= 1 AND `DaysPastDue` <= 15 THEN '1 to 15 days past due'
WHEN `DaysPastDue` >= 16 AND `DaysPastDue` <= 30 THEN '16 to 30 days past due'
WHEN `DaysPastDue` >= 31 AND `DaysPastDue` <= 60 THEN '31 to 60 days past due'
END
You can then follow the same pattern when creating your percentage calculation:
- SUM(CASE WHEN `DaysPastDue` <= 0 THEN `TotalDue`
WHEN `DaysPastDue` >= 1 AND `DaysPastDue` <= 15 THEN `TotalDue`
WHEN `DaysPastDue` >= 16 AND `DaysPastDue` <= 30 THEN `TotalDue`
WHEN `DaysPastDue` >= 31 AND `DaysPastDue` <= 60 THEN `TotalDue`
END)
/
MAX(`AllDue`)
That paired with the buckets beastmode will give you your values and series that you can use.
Let me know if you have any questions on this,
Valiant
**Please mark "Accept as Solution" if this post solves your problem
**Say "Thanks" by clicking the "heart" in the post that helped you.1 - CASE WHEN `DaysPastDue` <= 0 THEN 'Less than 0 days past due'
Categories
- All Categories
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 311 Workbench
- 7 Cloud Amplifier
- 9 Federated
- 3K Transform
- 114 SQL DataFlows
- 654 Datasets
- 2.2K Magic ETL
- 4.1K Visualize
- 2.5K Charting
- 806 Beast Mode
- 79 App Studio
- 44 Variables
- 761 Automate
- 189 Apps
- 480 APIs & Domo Developer
- 75 Workflows
- 17 DomoAI
- 40 Predict
- 17 Jupyter Workspaces
- 23 R & Python Tiles
- 408 Distribute
- 119 Domo Everywhere
- 279 Scheduled Reports
- 10 Software Integrations
- 141 Manage
- 137 Governance & Security
- 8 Domo Community Gallery
- 47 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 114 Community Announcements
- 4.8K Archive