Summing values in Table

I have a table with some calculated values in a column. It a simple math equation:
I’m displaying the results of {{Unit Price * Units)}} in a cell in every row.

I saw the video where you can sum dynamic values in a table and that works great

But is there a way I can sum all of my calculated fields in that table? Unlike the video, the values I want to sum are calculated in each row So like this:
Row1 cell {{UnitpriceUnits}}
Row2 cell {{Unitprice
Units}}
Row3 cell {{Unitprice*units}}

sum of row 1,2,3 = Grand Total.

Would this be better done in a query?

Thanks,
Chris

1 Like

can you share your sample table with us ?

I do not know of a real Wappler way of doing this, so I will suggest what I would do which is to keep track of the grand total using a session or cookie variable. See https://www.dmxzone.com/go/32875/working-with-sessions/

@turn3636

Firsth way (server side)

  1. create variable in your repat region ( case_result = {{CaseRate* Cases}} )
  2. create your table via table generator or manualy
  3. you will see variable and bind it into your table
  4. then sum it (client side) or you can sum them server side

Second way (client side )

  1. create variable client side
  2. enter your calculation into created variable {{CaseRate* Cases}}
  3. sum it

HI @s.alpaslan,

Thank you for explanation. But I follow you until point 3.
I make the variable
I make calculation for each row
How can I sum all the results? That s I don t understand

Thank you

please look screen shot for server side example ;

seconda way

    <dmx-serverconnect id="serverconnect1" url="dmxConnect/api/test/sum_new.php"></dmx-serverconnect>
    <div class="container">
      <table class="table">
        <thead>
          <tr>
            <th>Ukfid</th>
            <th>Ukf kat</th>
            <th>Ukf gun baslangic</th>
            <th>Ukf gun bitis</th>
            <th>Ukf fiyat</th>
          </tr>
        </thead>
        <tbody is="dmx-repeat" dmx-generator="bs4table" dmx-bind:repeat="serverconnect1.data.query1" id="tableRepeat1">
          <tr>
            <td dmx-text="ukfid"></td>
            <td dmx-text="ukf_kat"></td>
            <td dmx-text="ukf_gun_baslangic"></td>
            <td dmx-text="ukf_gun_bitis"></td>
            <td dmx-text="ukf_fiyat * ukf_gun_bitis"></td>
          </tr>
        </tbody>
      </table>
      <p><b>Total : {{serverconnect1.data.query1.sum(`ukf_fiyat * ukf_gun_bitis`)}}</b></p>
    </div>

@turn3636
Grand Total : {{ListTasks.data.ListTasks.sum(‘Cases* CaseRate’)}}
Please try

1 Like

I will! Thank you very much!

Thanks @s.alpaslan and @updates. I will try these out this morning! @ben I don’t know if the session variable will work in this case, but you just gave me some ideas about using it. I forgot all about it.

Chris

@s.alpaslan The second example you showed works perfectly. I don’t know how you thought of doing it that way, but thank you for the help. Coming from classic asp client side development is my weakness, but I’m learning more and more everyday.

2 Likes

@turn3636 @s.alpaslan Thank you so much for your question and the great answers:

I expanded on the client side option by putting it in a table footer so it stays attached to the selected table.
Following is an example:

Total = {{DC_Entries_Full.data.dc_entries_full.sum('Number')}}

You can .sum and also .count, which have allowed me to extend tables further.

One note is that this must be done in code as there is no Element yet for Table Footer.

Regards,

Brian

1 Like

:+1: