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
 10.6K All Categories
 8 Connect
 918 Connectors
 250 Workbench
 477 Transform
 1.8K Magic ETL
 69 SQL DataFlows
 478 Datasets
 218 Visualize
 260 Beast Mode
 2.1K Charting
 12 Variables
 19 Automate
 356 APIs & Domo Developer
 89 Apps
 3 Workflows
 20 Predict
 5 Jupyter Workspaces
 15 R & Python Tiles
 249 Distribute
 65 Domo Everywhere
 243 Scheduled Reports
 21 Manage
 42 Governance & Security
 191 Product Ideas
 1.2K Ideas Exchange
 11 Community Forums
 27 Getting Started
 14 Community Member Introductions
 55 Community News
 4.5K Archive