Nested Beast mode
Hi everyone,
I have some data like companyid, journeytype, ratingid and npsRating. With ratingid and npsRating, I usually calculate NPS (net promoting score) in beast mode like this:
(((Count(DISTINCT (CASE WHEN ((`npsrating` >= 9) AND (`npsrating` < 11)) THEN `ratingid` END )) - Count(DISTINCT (CASE WHEN (`npsrating` <= 6) THEN `ratingid` END ))) / count(DISTINCT `ratingid`)) * 100)
Now, my manager asked me to calculate NPS for each company, and then take the average over the NPS_percompany for each journeytype.
To solve this I know that I can put a window function and calculate NPS like this:
AVG((((Count(DISTINCT (CASE WHEN ((`npsrating` >= 9) AND (`npsrating` < 11)) THEN `ratingid` END )) - Count(DISTINCT (CASE WHEN (`npsrating` <= 6) THEN `ratingid` END ))) / count(DISTINCT `ratingid`)) * 100)) OVER (PARTITION BY `journeytype`)
as long as companyid exist in the groupby, the calculated amount for npe_per_journeytype is correct:
but as I wanna present it in a bar chart, I have to take out the companyId, and when it goes out from groupby, nps will be calculated for each journeytype, not per company and then take the average on journeytype:
What crossed my mind what that to have nested Beast mode as bellow:
AVG(AVG((((Count(DISTINCT (CASE WHEN ((`npsrating` >= 9) AND (`npsrating` < 11)) THEN `ratingid` END )) - Count(DISTINCT (CASE WHEN (`npsrating` <= 6) THEN `ratingid` END ))) / count(DISTINCT `ratingid`)) * 100)) OVER (PARTITION BY `companyid`, `journeytype` )) OVER (PARTITION BY `journeytype`)
but it does not work:
I cannot calculate this NPS in sql, because filters should apply on it on the fly, for example, companyType, filterdate, ... should be chose by the user.
Do you have any idea how I can tackle this problem?
Comments
-
You' can't have a window function inside a window function. Have you tried partitioning by the company Id and then the journey type since it sounds like you're wanting to break out your average NPS by both of those categories.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
Yes, but it did not solve our problem unfortunately.
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