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)
0
Categories
- All Categories
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 310 Workbench
- 7 Cloud Amplifier
- 9 Federated
- 3K Transform
- 113 SQL DataFlows
- 654 Datasets
- 2.2K Magic ETL
- 4K Visualize
- 2.5K Charting
- 796 Beast Mode
- 78 App Studio
- 44 Variables
- 757 Automate
- 188 Apps
- 480 APIs & Domo Developer
- 72 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