Is there something special about using SUM() in a ...
# general
m
Is there something special about using SUM() in a saved search formula? (Details in thread)
I have a custom record that has entries documenting hours used, unused, and total for a given month (1 per month). I then have a saved search that pulls back the records for a given month and I have a formula that determines the percentage of unused hours out of total. Formula works fine, unless I want to bring back multiple months data and calculate a percentage for the entire time period (as one percentage, not one per month.) Formula is like this... Round(Case When NVL({custrecord_monthlyhours_hours_allocated}-{custrecord_monthlyhours_hours_logged},{custrecord_monthlyhours_hours_allocated}) < 0 Then 0 Else NVL({custrecord_monthlyhours_hours_allocated}-{custrecord_monthlyhours_hours_logged},{custrecord_monthlyhours_hours_allocated}) End / {custrecord_monthlyhours_hours_allocated},2) NVL is used to equate null to 0, and I have logic to avoid divide by 0. So this works perfectly, as long as I get one record back such as - Returned Record 1 (Month 1) hours_allocated=100 hours_logged=20 Answer - 20% However this obviously doesn’t work if I have Returned Record 1 (Month 1) hours_allocated=100 hours_logged=20 Returned Record 2 (Month 2) hours_allocated=100 hours_logged=30 Answer should be hours_allocated=200 hours_logged=50 Percentage - 25% I can’t use the summary type of SUM, as it will add the percentages. Average doesn’t come out accurately. So, long story short... I’m trying to use SUM() after the Round(), or around the math in the case statement, but unfortunately, I’m getting an invalid expression on every scenario I try and don’t understand the cause of the invalid expression. For instance - Round(SUM(Case When NVL({custrecord_monthlyhours_hours_allocated}-{custrecord_monthlyhours_hours_logged},{custrecord_monthlyhours_hours_allocated}) < 0 Then 0 Else NVL({custrecord_monthlyhours_hours_allocated}-{custrecord_monthlyhours_hours_logged},{custrecord_monthlyhours_hours_allocated})) End / SUM({custrecord_monthlyhours_hours_allocated}),2) But I’ve tried a bunch of permutations. Any ideas?
s
Build your formula in suite analytics and use the formula checker, it should tell you what is wrong with your formula.
m
Thanks, will give that a shot. I think it needs to be paired with a case statement to group them.