How to count distinct based on the sum of another column?
I dataset with a list of "pulls" for each day and the "setter" associated with that pull. I have a calculation through the ETL for this dataset that sums up the total sales per setter for the previous 30 days. My objective is to count the number of distinct setters who have a sum of 0 total sales for the time range filtered on the card. How would I do this on a beast mode? I can't do this through ETL as I need this count to work dynamically based on the date range the user chooses for the card.
Ex:
If I were to look at the distinct number of setters for 9/30/22 the number would be 1 because Test User 1's sum of total sales in the last 30 days exceeds 0 and Test User 2's total is 0, so Test User 1 does not count in the setter count but Test User 2 does.
If I were to look at the distinct number of setters for 9/25/22  9/30/22 the total would be 0 as both test user's sum of total sales would exceed 0 for that time frame.
Is this calculation possible through a beastmode?
Best Answer

Hi @lb1234 ,
Assumption  The 3 columns "Pull Date" (A), "Setter"(B) and "Total Sales Last 30 Days"(C) are coming from the ETL.
What I understand from the example is, if the count of "Total Sales Last 30 Days" is greater than 0, it should not be counted. Which conversely means, if there was no sale in the past X many days, then that be counted as 1?
So you could write it as,
COUNT(DISTINCT (CASE WHEN SUM( `Total Sales Last 30 Days`) = 0 THEN `Setter` END)) OVER (PARTITION BY `Setter`)
This would work. Attaching Test Data
Let me know if this does not work for you!
Thanks
Aditya Jain
'Happy to Help'0
Answers

Hi @lb1234 ,
Assumption  The 3 columns "Pull Date" (A), "Setter"(B) and "Total Sales Last 30 Days"(C) are coming from the ETL.
What I understand from the example is, if the count of "Total Sales Last 30 Days" is greater than 0, it should not be counted. Which conversely means, if there was no sale in the past X many days, then that be counted as 1?
So you could write it as,
COUNT(DISTINCT (CASE WHEN SUM( `Total Sales Last 30 Days`) = 0 THEN `Setter` END)) OVER (PARTITION BY `Setter`)
This would work. Attaching Test Data
Let me know if this does not work for you!
Thanks
Aditya Jain
'Happy to Help'0 
Thank you so much!!!!
0 
@Aditya_Jain That worked when looking at a single value card but when I'm looking at the count for the last 13 weeks in a bar graph, I'm running into issues as it's not grouping the days into weeks. Do you know why this would be?
0 
@Aditya_Jain when I try and get an average of the number of tasks by setter using that calculation, I'm getting a divide by 0 error. How do I fix this? Here is my calculation:
COUNT(DISTINCT `Task.ActivityID`) / (COUNT(DISTINCT (CASE WHEN SUM(`Is Setter`) = 0 THEN `Setter.FullName` END)) OVER (PARTITION BY `Setter.FullName`))
0 
Apologies for late reply
on this calculation, not going into the correctness of the formula, but trying to resolve divide by zero
COUNT(DISTINCT `Task.ActivityID`) / (COUNT(DISTINCT (CASE WHEN SUM(`Is Setter`) = 0 THEN `Setter.FullName` END)) OVER (PARTITION BY `Setter.FullName`))
I assume this is part of a case statement,
to avoid divide by zero, please put a case before this, where you can check if your denominator which I suppose i s ' (COUNT(DISTINCT (CASE WHEN SUM(`Is Setter`) = 0 THEN `Setter.FullName` END)) OVER (PARTITION BY `Setter.FullName`)) ', if this is already 0, then please make the entire calculation as 0.
Please let me know if this works.
Thanks
Aditya Jain
'Happy to Help'0 
@Aditya_Jain it still did not work. I've wrapped it in a case statement, please see below:
Case when (COUNT(DISTINCT (CASE WHEN SUM(`Is Setter`) = 0 THEN `Setter.FullName` END)) OVER (PARTITION BY `Setter.FullName`)) = 0 then 0 else COUNT(DISTINCT `Task.ActivityID`) / COUNT(DISTINCT (CASE WHEN SUM(`Is Setter`) = 0 THEN `Setter.FullName` END)) OVER (PARTITION BY `Setter.FullName`) end
0 
Hi, can you please provide a sample dataset with the mentioned columns so that I can test it and let you know a solution.
'Happy to Help'0
Categories
 All Categories
 1.7K Product Ideas
 1.7K Ideas Exchange
 1.5K Connect
 1.2K Connectors
 292 Workbench
 4 Cloud Amplifier
 8 Federated
 2.8K Transform
 95 SQL DataFlows
 602 Datasets
 2.1K Magic ETL
 3.7K Visualize
 2.4K Charting
 695 Beast Mode
 43 App Studio
 39 Variables
 658 Automate
 170 Apps
 441 APIs & Domo Developer
 42 Workflows
 5 DomoAI
 32 Predict
 12 Jupyter Workspaces
 20 R & Python Tiles
 386 Distribute
 111 Domo Everywhere
 269 Scheduled Reports
 6 Software Integrations
 113 Manage
 110 Governance & Security
 8 Domo University
 30 Product Releases
 Community Forums
 39 Getting Started
 29 Community Member Introductions
 98 Community Announcements
 Domo Community Gallery
 4.8K Archive