Using Sum vs AVG for period Comparison

Hi,
The column I am trying to fix is 'Current Month'. The goal is to use a variable to switch between different metrics. When I use Sum in front of my case statements I achieve the current months number, however I need the averages for the %s. When I switch it to avgs the number gets cut in half every time I switch the time frame( Example: Last 3 Months, Last 4 months, etc…)
The correct number for this row should be 54%, which I get when I select 'This Month' in the top right.
However as soon as I select any other time frame it gets cut in half? This doesnt happen to my revenue (which is using a SUM in front of the case statement).
Selecting this month for revenue.
Selecting Last 3 months for Revenue.
Why Might this be the case?
CASE WHEN Comparison Type
= 'Revenue' THEN
(SUM(CASE WHEN LAST_DAY(Fiscal Months
) = LAST_DAY(CURDATE()) THEN Revenue
ELSE 0 END))
WHEN Comparison Type
= 'Driving%' THEN
Avg(CASE WHEN LAST_DAY(Fiscal Months
) = LAST_DAY(CURDATE()) THEN (Driving%
) ELSE 0 END)
WHEN Comparison Type
= 'Empty%' THEN
Avg(CASE WHEN LAST_DAY(Fiscal Months
) = LAST_DAY(CURDATE()) THEN Emptypercent
ELSE 0 END)
END
Answers
-
Can you provide more clarity as to what the Driving% column is (is it a calculated field with an existing aggregation, or is it a pre-calculated number?) and provide a sample of what the data structure is underlying for a couple of rows?
0 -
JasonAltenburg
I figured out a solution, I basically had to sum the column then divide the column to get the results to be static for that month.
Solution is as follows
IFNULL(CASE
WHENComparison Type
= 'Revenue' THEN
ROUND(SUM(CASE
WHEN LAST_DAY(Fiscal Months
) = LAST_DAY(CURDATE()) THENRevenue
ELSE 0
END), 0)- WHEN `Comparison Type` = 'Driving%' THEN
- ROUND(
- SUM(CASE
- WHEN LAST_DAY(`Fiscal Months`) = LAST_DAY(CURDATE()) THEN `Driving%`
- ELSE 0
- END)
- / COUNT(CASE
- WHEN LAST_DAY(`Fiscal Months`) = LAST_DAY(CURDATE())
- THEN `DriverName`
- END) * 100, 2
- )
- WHEN `Comparison Type` = 'Empty%' THEN
- ROUND(
- SUM(CASE
- WHEN LAST_DAY(`Fiscal Months`) = LAST_DAY(CURDATE()) THEN `Emptypercent`
- ELSE 0
- END)
- / COUNT(CASE
- WHEN LAST_DAY(`Fiscal Months`) = LAST_DAY(CURDATE())
- THEN `DriverName`
- END) * 100, 2
- )
END,0)
1 - WHEN `Comparison Type` = 'Driving%' THEN
Welcome!
Welcome!
Categories
- All Categories
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 308 Workbench
- 6 Cloud Amplifier
- 10 Federated
- 3.8K Transform
- 660 Datasets
- 117 SQL DataFlows
- 2.2K Magic ETL
- 815 Beast Mode
- 3.3K Visualize
- 2.5K Charting
- 84 App Studio
- 46 Variables
- 780 Automate
- 191 Apps
- 482 APIs & Domo Developer
- 84 Workflows
- 23 Code Engine
- 41 AI and Machine Learning
- 20 AI Chat
- 1 AI Playground
- 2 AI Projects and Models
- 18 Jupyter Workspaces
- 413 Distribute
- 121 Domo Everywhere
- 281 Scheduled Reports
- 11 Software Integrations
- 145 Manage
- 141 Governance & Security
- 8 Domo Community Gallery
- 49 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 115 Community Announcements
- 4.8K Archive