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
 7.6K All Categories
 Connect
 913 Connectors
 241 Workbench
 470 Transform
 1.8K Magic ETL
 60 SQL DataFlows
 445 Datasets
 24 Visualize
 194 Beast Mode
 2K Charting
 6 Variables
 1 Automate
 348 APIs & Domo Developer
 82 Apps
 Workflows
 14 Predict
 3 Jupyter Workspaces
 11 R & Python Tiles
 241 Distribute
 59 Domo Everywhere
 241 Scheduled Reports
 14 Manage
 35 Governance & Security
 18 Product Ideas
 1.1K Ideas Exchange
 Community Forums
 15 Getting Started
 1 Community Member Introductions
 49 Community News
 18 Event Recordings
 579 日本支部