SUM with multiple conditions
Hello everyone,
I am having trouble with a DOMO Beast mode sum Calculation. Below you will find my existing calculation. I am looking to add the value of all records that have a date to Customer in column A and exclude those records in column B that have a payment date. Essentially I am looking to calculate the value of invoices sent to the Customer and of those who has not submitted payment yet.
Issue: It appears that I am still adding values to my total when payment dates are present.
Can someone please help me to improve my beast mode calculation?
SUM(
CASE
WHEN ` Date To Customer` IS NOT NULL AND `Payment Date` IS NULL THEN (`USD`)
END
)
Answers
-
Hi @user066906
Typically when I have a complex beastmode that isn't functioning as expected I'll break it down into different beast modes and toss them onto a table card to help investigate each portion.
Does your payment check return what you're expecting on it's own without the SUM for each record?
CASE WHEN `Payment Date` IS NULL THEN `USD` END
CASE WHEN `Date To Customer` IS NOT NULL THEN `USD` END
CASE WHEN `Date To Customer` IS NOT NULL AND `Payment Date` IS NULL THEN `USD` END
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**2 -
Agree with @GrantSmith . I would also add in an ELSE statement into the test logic and the final logic to ensure that it is evaluating the NULLS correctly. You could have blanks instead of nulls which would cause this statement to not return the results you are expecting. If you are actually have blanks you could do something like this:
SUM( CASE WHEN ` Date To Customer` '1/1/1900' AND (`Payment Date` IS NULL OR TRIM(`Payment Date`) = '') THEN (`USD`) ELSE 0 END )
Hope this helps.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1 -
@user066906 are your invoices and payment records on the same row? or are they spread across rows? if it's spread across rows these solutions we're proposing won't work for you... so ... make sure to double check.
@MarkSnodgrass 's checks for is null OR is blank are perfect, but just do the opposite check as proposed by @GrantSmith for the dateToCustomer
sum( case when (`date to customer` is not null AND trim(`date to customer`) <> '') AND (`Payment Date` IS NULL OR TRIM(`Payment Date`) = '') THEN `USD` end )
Note the difference between AND and OR.
most of the time, you don't need ELSE 0 when you're aggregating.
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"2 -
Hi, I tried your solution and I still receive the same results. It looks like I am still pulling in blank values for 'date to Customer' and payment dates with values. I have tried many variations of the suggestions and still seem to get the same results.
All of the data for each record is in the same row.
Do you have any other ideas?
0 -
the code that everyone gave you is correct. the problem is in your understanding of your data and how you're testing your data.
if you can't identify your data with s not null and empty string, then it must contain SOMETHING that you aren't testing for. figure out what the something is.
alternatively, post a sample of your data.
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
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 622 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 744 Beast Mode
- 58 App Studio
- 41 Variables
- 686 Automate
- 176 Apps
- 453 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 395 Distribute
- 113 Domo Everywhere
- 276 Scheduled Reports
- 6 Software Integrations
- 125 Manage
- 122 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