Dividing in SQL
I currently have this code: categorizing some leads.
Select
`Year-Month`
,`Lead Source`
,`Product Line`
,`Product Models`
,`Country`
,`Early Stage No Movement`
,`Stage 0 to Early`
,`Early to Lost`
,`Early to Won`
,`Early to Late`
,`Late to Lost`
,`Late to Won`
,Sum(`Early to Lost`+`Early to Won`+`Early to Late`) AS 'Total Low to High'
,SUM(`Early Stage No Movement`+`Stage 0 to Early`+`Early to Lost`+`Early to Won`+`Early to Late`+`Late to Lost`+`Late to Won`) AS 'Total'
FROM `aggregation_categorization`
GROUP BY
`Year-Month`
,`Lead Source`
,`Product Line`
,`Product Models`
,Country
This runs fine, the next thing I am trying to do is add in the %.
SELECT *
,`Total Low to High`/`Total` AS '% Of Low to High'
FROM `formulas`
This works fine as well, but when I place it in a sumo table aggregating it does work. Any suggestions would be awesome.
Thank you.
Best Answer
-
Given the math you've put on the screen, there is no reason to run this ETL as a SQL transform. Just keep your data unaggregated.
Be careful with
Sum(`Early to Lost`+`Early to Won`+`Early to Late`) AS 'Total Low to High'
for any row, if any column contains the value null, the entire result will be null. this is the appropriate adjustment.
Sum(ifnull(`Early to Lost`,0) +ifnull(`Early to Won`,0)+ifnull(`Early to Late`,0) ) AS 'Total Low to High'
to do the division you're describing, just calculate the ratio in a beast mode (you may have to build the beast mode in analyzer, then share it to the dataset in order to reference it in a sumo card.
Personally i recommend you don't use the Sumo card and just use the Pivot Table card in Analyzer.
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"1
Answers
-
Hi @gbennett
Did you mean to say aggregating it doesn’t work? How does it currently work and how are you expecting it to work?
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
Hey Grant,
I would think, that if I pulled the data in a sumo card, I could group specifically on a year-month and product line and it would provide the % of Low to High. But rather it adds the % of Low to High for all records. I hope that makes sense.
I appreciate your help.
Thanks.
0 -
I was able to use Sum(ifnull(`Early to Lost`,0) +ifnull(`Early to Won`,0)+ifnull(`Early to Late`,0) ) AS 'Total Low to High'
and enter in a beast mode.
0
Categories
- 7.7K All Categories
- 3 Connect
- 919 Connectors
- 244 Workbench
- 477 Transform
- 1.8K Magic ETL
- 60 SQL DataFlows
- 446 Datasets
- 37 Visualize
- 198 Beast Mode
- 2K Charting
- 8 Variables
- 1 Automate
- 348 APIs & Domo Developer
- 82 Apps
- Workflows
- 14 Predict
- 3 Jupyter Workspaces
- 11 R & Python Tiles
- 241 Distribute
- 59 Domo Everywhere
- 241 Scheduled Reports
- 15 Manage
- 36 Governance & Security
- 27 Product Ideas
- 1.1K Ideas Exchange
- Community Forums
- 14 Getting Started
- 1 Community Member Introductions
- 49 Community News
- 18 Event Recordings
- 579 日本支部