Weighted Average formula  beast mode
Hi all
I am using a beast mode to calculate the weighted average of days between two dates (payment due date and invoice date). Formula here: SUM((`PAYMNT_DUE_DT``INVOICE_DT`)*`RECPT_AMT_USD`)/ SUM(`RECPT_AMT_USD`)
However, I realized there may be some zeros in the output that are possibly causing the weighted average to be skewed lower. Can someone let me know if there is something I should add to exclude zeros maybe?
Answers

Sum(Case when (your function) = 0 then 0 else (your function) end)
0 
You can use a CASE statement to filter some values in your calculation. See
CASE WHEN `value_or_expression` <> 0 THEN `value` END
Alternatively you could use the filter on your card to filter out other values.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 
SUM((`PAYMNT_DUE_DT``INVOICE_DT`)*`RECPT_AMT_USD`)/ SUM(`RECPT_AMT_USD`)
I don't believe your problem is the existence of zeros. Or att least, perhaps not the way you're explainig it anyway.
1) i assume payment_due_dt is a dateTime column. If so, you shouldn't do dtdt, I'm not sure it's reasonable to assume that Domo will calculate the difference between two dates. Instead, use the DateDiff function. Be clear if it's dateTime or just date, b/c you might get a decimal result if it's less than a complete date.
Lastly, what happens if payment came in on the same day as the invoice? then, yes the datediff is zero, so i assume that's where you want your CASE statement, if datediff = 0 then 1 else datediff end.
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.1K Product Ideas
 1.1K Ideas Exchange
 1.2K Connect
 966 Connectors
 254 Workbench
 Cloud Amplifier
 1 Federated
 2.4K Transform
 75 SQL DataFlows
 499 Datasets
 1.8K Magic ETL
 2.7K Visualize
 2.2K Charting
 360 Beast Mode
 19 Variables
 483 Automate
 101 Apps
 378 APIs & Domo Developer
 6 Workflows
 22 Predict
 6 Jupyter Workspaces
 16 R & Python Tiles
 316 Distribute
 64 Domo Everywhere
 252 Scheduled Reports
 59 Manage
 59 Governance & Security
 1 Product Release Questions
 5K Community Forums
 37 Getting Started
 23 Community Member Introductions
 63 Community Announcements
 4.8K Archive