Simple count of unique responses by location
This should be easy I think.
I have an app that produces survey response data in a pattern something like the simple example shown. Each row is a response to a question, and each response is tagged with a "ResponseGroupID" that ties them together as having been entered as part of a single "batch". I'm finding it easy to aggregate individual response values (not shown below) but I'm having trouble simply counting how many "batches" (as identified by their ResponseGroupID) each location has.
Table I would like
Table I get
Using a mega-table and adding location and my calculated field
The formula I'm using in 'Distinct ResponseGroupIDs is
Not sure if I have to create separate grouped by tables in the data flow but I'm trying to avoid additional complexity when possible and this seems as though it should be simple. Using Sum(COUNT(DISTINCT `ResponseGroupID`) in the calculated field doesn't work. Should this be done in the SQL flow that produces the model?
So I did achieve the results I desired in this case but not sure if this is the most efficient design pattern.
In my Data Flow, I created a new table
Select `LocationID`, `Location`, COUNT(DISTINCT `ResponseGroupID`) as 'Distinct ResponseGroupID' From `ajh_rounding_recursive_final_output` Group BY `LocationID`
Then joined this new table to the main output (shown in the second LEFT JOIN below)
SELECT rm.`Measure` AS "RoundingMeasures.Measure", rm.`Section` AS "RoundingMeasures.Section", rm.`ID` AS "RoundingMeasures.ID", rd.`MeasureID` , rd.`ID` , rd.`ResponseGroupID` , rd.`Comments` , rd.`Created` , rd.`Date` , rd.`SubmittedBy`, rd.`Location` , rd.`LocationID` , rgi.`Distinct ResponseGroupID` FROM `tbl_rounding_data` rd LEFT JOIN `ajh_rounding_measures` rm ON rd.`MeasureID` = rm.`ID` LEFT JOIN `tbl_responsegroupids_by_location` rgi ON rd.`LocationID` = rgi.`LocationID`
Then, in a data card, I can use "MAX" as an aggregation (each value is the same for every entry of the location) and it gives me what is shown below.
Location Distinct ResponseGroupIDs 6B 2 5LW 1
My question is, is this this the best way to do this? If I wanted to count how many distinct ResponseGroupIDs there were by person, do I have to build this out as a separate table too (I don't mind, just want to make sure I'm not missing a much easier way to approach this)?
Thanks for reading and for your recommendations!0
While this seemed to give the results I desired, there is no way to filter by any of the many dimensions so this won't really work.
Still looking for some direction on this, thanks.0
Hi @PhilD ,
Are the only two fields you have listed the location and your count distinct calculated field? If that's the case then your locations might appear the same but aren't actually the same (perhaps a trailing space).
Can you try wrapping your location in a new beast mode to strip any trailing spaces?
TRIM(`Location`)**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0
The locations come from a table in the app so they are the same.
Funny thing, I actually created a new card from scratch and my first attempt worked (I thought that it should). I had both cards open side by side and verified everything was absolutely positively identical and the first on kept giving me the results I shared. After I recreated it fresh, the simple formula worked... not sure what was going here but I wish I could have back the hours I wasted ?0
@PhilD instead of JOINING the aggregated values to your transactional data, make your dataset TALLER instead of wider.
Create a section of data where ActivityType = Actual. Then UNION your aggregation where ActivityType = GroupByResponseGroup (or whatever your appropriate group by clause is).
In your beast mode use
-- metrics in numerator
sum( CASE WHEN ActivityType = Actual Then ... ) /
--- group by in denominator
sum( CASE WHEN activity TYpe = GroupByResponseGroup Then ...)
Try to avoid count distinct by reshaping your data to have a metric column with a 1 or a 0 to represent a summable count.
If you provide a decent dataset, i can make a long-form tutorial on this b/c it is a recurring question in the Dojo.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"0
- 7.7K All Categories
- 12 Connect
- 925 Connectors
- 247 Workbench
- 441 Transform
- 1.7K Magic ETL
- 61 SQL DataFlows
- 456 Datasets
- 88 Visualize
- 222 Beast Mode
- 2.1K Charting
- 8 Variables
- 35 Cards, Dashboards, Stories
- 5 Automate
- 349 APIs & Domo Developer
- 85 Apps
- 17 Predict
- 3 Jupyter Workspaces
- 14 R & Python Tiles
- 242 Distribute
- 60 Domo Everywhere
- 241 Scheduled Reports
- 18 Manage
- 39 Governance & Security
- 46 Product Ideas
- 1.1K Ideas Exchange
- 6 Community Forums
- 19 Getting Started
- 6 Community Member Introductions
- 50 Community News
- 18 Event Recordings
- 577 日本支部