Calculating percent of total with values that count in multiple categories
I'm trying to develop a card for diverse business participation reporting. A single business may have multiple diversity classifications, and can be counted towards each. However, when we are looking at the total, we are looking at the total of distinct businesses.
Example data:
I want the card to have flexibility to modify the data range, and still have the calculations correct, so I'm trying to do this in beast mode instead of in an ETL. I'm trying to get to something like this (where each example below is the same card but filtered by date range):
I tried taking my dataset and appending rows that were labeled as TOTAL but that didn't work (sum(spend)/sum(case when category = 'TOTAL' then spend end) since at the row level the category is either TOTAL or one of the above. I thought about doing the aggregation in the ETL and creating a new column for total... but given the desire for data flexibility I'm trying to avoid that path.
Has anyone done something like this before or have suggestions?
Answers
-
@mhouston assuming you have window functions in beast mode enabled in your instance, you should be able to use this to get the percent of total:
sum(amount) / sum(sum(amount)) over ()
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
@MarkSnodgrass how would you structure the over clause? I couldn't figure out how to do that to get the amount for the distinct businesses.
0 -
Try adding a partition by if you want to be the percent of that business name
sum(amount) / sum(sum(amount)) over (PARTITION BY `BusinessName`)
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
I don't want it to be a percent of business name, but the total spend for the category divided by the total spend across all distinct businesses. So like in the example data I put, I want the total women owned business spend (1000+3000) divided by the total spend across distinct businesses (1000+2000+3000) = 67%. The 1000 spend for business A can be counted in each category (small, woman, minority), but we've only spent it once, so in the total dollars it should only be counted once.
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive