Table Subtotal not calculating beast mode

Hi, I have a table with below records. The subtotal for % column is simply adding the values instead of applying the beast mode calculation at the subtotal level. 2016 Total row % should be 34% instead of 49% and 2017 should be 35% instead of 62%. Has something changed with recent releases?

 

YearSourceSubmission CountIssued CountSub vs issued
2016A961213%
 B145051736%
2016 Total 154652949%
2017A741926%
 B196270336%
2017 Total 203672262%

 

Best Answer

  • jaeW_at_Onyx
    jaeW_at_Onyx Budapest / Portland, OR 🟤
    Accepted Answer

    interesting.  I'll be honest I didn't test this, but I'm pretty confident the pivot table is acting as expected.

     

    In your math, ignoring the adjustment to change units from year to months, you've said

    "for each row, take issued count and divide it by submission count THEN take the sum."

     

    what i believe you want is:  "take total issued count divided by total submission count."

     

    In that case, your base math should be:

    sum(issued count) / sum(submission count)

     

    VERIFY THAT THIS MATH IS CORRECT

     

    IF SO, then to accommodate for your adjustment for the current year, nest your CASE statement INSIDE the SUMs.

     

    sum(

    issued count / case when year ... then 12 else month(curdate()) end

    ) /

    sum(

    submission count / case when year ... then 12 else month(curdate()) end

     

    Hopefully that makes sense.

     

     


    @user016969 wrote:

    Hi, My beast mode calc is -

    case
    when `Year` != YEAR(CURDATE())
    then (`Issued Count`/ 12) / (`Submission Count`/ 12)
    else (`Issued Count`/ MONTH(CURDATE()))/ (`Submission Count`/ MONTH(CURDATE()))
    end


     

Answers

  • jaeW_at_Onyx
    jaeW_at_Onyx Budapest / Portland, OR 🟤

    oh interesting!  what's your beast mode calc? (this might be something to raise to support)

  • Hi, My beast mode calc is -

    case
    when `Year` != YEAR(CURDATE())
    then (`Issued Count`/ 12) / (`Submission Count`/ 12)
    else (`Issued Count`/ MONTH(CURDATE()))/ (`Submission Count`/ MONTH(CURDATE()))
    end

  • Thanks but 'Subtotal' record should perform that logic. I removed all case statement and simply made the beast mode with 'Issued count / submission count'. Still, subtotal record does not calculate this baest mode and simply adds values. e.g. 2016 Total record should calculate 529/1546, but what it does is 13 (% of A) + 36 (% of B) giving 49. I observed that at column level there is 'Subtotal/Total' option that is by default set to 'Sum'. My guess is that this sum overrides beast mode calculation for subtotal row. I think the column level drop down should have additional option where user wants beast mode to be calculated instead of listed calculations (Max, Min, Avg, Count and Sum).

  • May be I should clarify that the 'Total' records are calculated using 'Subtotal' chart property and Sub vs. Issued is a beast mode calc. Original data is as follows:

    YearSourceSubmission CountIssued Count
    2016A9612
    2016B1450517
    2017A7419
    2017B1962703

     

    After beast mode addition it is -

    YearSourceSubmission CountIssued CountSub vs issued
    2016A961213%
     B145051736%
    2017A741926%
     B196270336%

     

    After adding chart property of subtotal it becomes as noted in original question. So when added subtotal, 'Sub vs Issued' column should also calculate beast mode for the subtotal record.

  • GrantSmith
    GrantSmith Indiana 🔴

    @user016969 - This is because how the Sub Total option works. It doesn't know anything about your beast mode but rather it's just adding up all of the previous row values. This is why you're getting 13% + 36% = 49% rather than 529 / 1546 = 34%. It's because of the order of operations used to calculate your percentage.

     

    Put in more mathematical terms this is how the Sub Total is processing your data:

    (12 / 96 ) + (517 / 1450)

    Instead of the expected:

    ( 12 + 517 ) / ( 96 + 1450 )

     

    This is why @jaeW_at_Onyx metioned wrapping your fields in a SUM() aggregation so that the addition will be done first before the division.

     

    SUM(`Issued Count`) / SUM(`Submission Count`)

    Utilizing that beast mode gets you the expected results:

    Screen Shot 2020-06-16 at 3.50.28 PM.png

  • ok, now I understand. Thank you! yes it worked!