FIXED BY referenced in another beast mode

Hello everyone,
I am trying to reference a beast mode (streak) to another (streak_breaker) that's using a FIXED (BY) function, but it keeps on returning an error. Is this not feasible?
Here's my example data and calculations:
- streak_breaker = MAX(MAX(CASE WHEN
status
= 'draft' THENcampaign_id
END) FIXED (BYaccount_id
)) » Gets the latest campaign that wasn't sent per account - streak = COUNT(CASE WHEN
campaign_id
>dynamic_streak_breaker
THENcampaign_id
END) » Counts the number of campaigns published later than the one that wasn't sent
If only this two works together, I can count the sent streak accurately even if I do not filter anything, which would result to 6, as the streak_breaker
would be 4 and there are 6 campaigns more than 4, or if I filter Sponsor 1, which would result to 5, as the streak_breaker
would switch to null/0
campaign_id | sponsor | status |
---|---|---|
10 | sponsor2 | sent |
9 | sponsor 1 | sent |
8 | sponsor2 | sent |
7 | sponsor 1 | sent |
6 | sponsor2 | sent |
5 | sponsor 1 | sent |
4 | sponsor2 | draft |
3 | sponsor 1 | sent |
2 | sponsor2 | sent |
1 | sponsor 1 | sent |
Actually, even if I changed the streak_breaker to the below formula , the streak beastmode will validate but the chart will still throw an error
MAX(CASE WHEN status
= 'draft' THEN campaign_id
)
Best Answer
-
It’s because you have an aggregate inside an aggregate which isn’t allowed. You could attempt to use a window function so the max is returned for each row depending on your partitions and then do the count on that value
COUNT(CASE WHEN `campaign_id` > MAX(`latest_unsent_campaign_acct`) FIXED (BY `your_partition_field_or_remove_by_clause`) THEN `campaign_id` END)
Window or fixed functions will return a single value for each row which will allow you to then aggregate.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0
Answers
-
It’s because you have an aggregate inside an aggregate which isn’t allowed. You could attempt to use a window function so the max is returned for each row depending on your partitions and then do the count on that value
COUNT(CASE WHEN `campaign_id` > MAX(`latest_unsent_campaign_acct`) FIXED (BY `your_partition_field_or_remove_by_clause`) THEN `campaign_id` END)
Window or fixed functions will return a single value for each row which will allow you to then aggregate.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0
Categories
- All Categories
- Product Ideas
- 2.1K Ideas Exchange
- Connect
- 1.3K Connectors
- 309 Workbench
- 7 Cloud Amplifier
- 10 Federated
- Transform
- 664 Datasets
- 120 SQL DataFlows
- 2.3K Magic ETL
- 824 Beast Mode
- Visualize
- 2.6K Charting
- 87 App Studio
- 46 Variables
- Automate
- 195 Apps
- 486 APIs & Domo Developer
- 90 Workflows
- 24 Code Engine
- AI and Machine Learning
- 23 AI Chat
- 4 AI Projects and Models
- 18 Jupyter Workspaces
- Distribute
- 119 Domo Everywhere
- 283 Scheduled Reports
- 11 Software Integrations
- Manage
- 143 Governance & Security
- 11 Domo Community Gallery
- 49 Product Releases
- 13 Domo University
- Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 116 Community Announcements
- 5K Archive