Okay
  Public Ticket #2966315
Calculate values from column sum
Closed

Comments

  • Todd McMahon started the conversation

    Is it possible to display a formula result based on the sum of two columns? We are creating attendance records for events. Each event has a different number of attendees, separated by gender. 

    For example:
    Event 1: 8 of 10 males were present and 2 of 10 females were present. (80% Male participation and 20% Female participation - 50% Total participation)

    Event 2: 70 of 100 males were present and 50 of 100 females were present. (70% Male participation and 50% Female participation - 60% Total participation)

    We built a participation percentage column for each event, but I need to accurately display the total percentage for both events. Averaging the participation column is inaccurate because it simple averages 50% and 60% (55%). What we really need to do is calculate the average off the columns sums (78 of 110 male = 70.9%, 52 of 110 female = 47.27% for a total of 130 of 220 = 59.09%

    I would then like to display the formulated result via shortcode and have it follow filtering.

  •  2,572
    Aleksandar replied

    Hello Todd

    You can create a formula column what would calculate the SUM of two columns, but if you were planning on using the calculation functions in the formula column - unfortunately that is not possible.

    I don't quite understand if these events are saved as rows or columns in your table, so I can't provide better advice. Can you please show me what the table looks like, and a mockup of what you want to see? I will gladly provide some advice based on that.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Todd McMahon replied

    Hi Aleksandar, 

    Each event is a row and has Eligible, Attended and the Participation Percentage per event. I want to display a total participation percentage for all events based off the total eligible and total attended numbers. I've attached a screen shot that may help clear things up a little. 

  •  2,572
    Aleksandar replied

    Hey Todd

    Unfortunately, as mentioned in the previous response, you wouldn't be able to use the calculation functions in a Formula column, so adding 57 to 63 and then displaying the average from that is not possible with the plugin's built-in features.

    You could, however, create a new MySQL query-based table where you would use the query to calculate the SUMS of these two columns. Something like this:

    SELECT SUM(eligible) as eligible, SUM(attended) as attended
    FROM wp_wpdatatable_67
    

    Where "eligible" and "attended" are origin headers of the columns of the original table, and the "wp_wpdatatable_67" is changed to reference the "MySQL table name for editing" in the Editing tab of the original table:

    7526907935.png
    5413714232.png

    So, just replace the origin header names and the table name in the query, and you'll get a table like this:

    1625859941.png

    Then, you'd be able to calculate the average using a Formula column with a formula like:

    9825049937.png

    So, the result in that formula column would be 78.9 (for values above). You'd also be able to add a suffix " %" to the formula column:

    3103519180.png

    So the final result is this:

    7139767467.png

    It's a bit more work, but if you were to remove the calculation functions from the original table, and add this MySQL query-based table below, it would automatically calculate these values with each new entry.

    I hope that helps.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Todd McMahon replied

    Hi Alexsandar, 

    Thanks for the followup. I don't see an 'Editing' tab in the original table. I took a screenshot of what I see. Is there an option somewhere to display/hide the editing tab. Is it available on a table with Formidable Form as the data source?

  •  2,572
    Aleksandar replied

    Hi again Todd

    Unfortunately, tables created from Formidable Forms are not editable, and that's why you don't see the Editing tab.

    These tables are generated by a programmatically created query that runs in the back, and the data is actually pulled from multiple database (formidable's) tables.

    In this case, I'm afraid you won't be able to achieve what I advised in my last response.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables