When I run the following mysql query in Workbench it returns the desired result (see attachment).
set @csum := 0; select condofee_date as Date, condofee_description as Description, condofee_amount as Amount, (@csum := @csum + condofee_amount) as Balance FROM condominium_fees WHERE apartments_apartment_id = 1 ORDER BY condofee_date;set @csum := 0;
If I run it on your plug in I get;
cannot calculate position of @csum := 0 @csum := 0 within @csum := 0; select condofee_date as Date, condofee_description as Description, condofee_amount as Amount, (@csum := @csum + condofee_amount) as Balance FROM condominium_fees WHERE apartments_apartment_id = 1 ORDER BY condofee_date;set @csum := 0;
Unfortunately, using variables ( @ ), stored procedures and nested queries is not supported, but you can prepare a MySQL view (which will return the data you need); call it “view1” for example, and then build a wpDataTable based on a simple query like “SELECT * FROM view1”.
I'm pretty sure mysql doesn't allow variables in a view either. Is there a way I can display a running balance calculated from the previous 2 columns on each row in wpdataTables?
I had looked at this but couldn't see a way of creating a formula that references a cell in the previous row? Do you have an example of using the formula column to create a running total type arrangement?
You can't choose a specific cell, but when creating a Formula Column, you can include (select columns from the modal) the column and use it for the formula, so like: col1*((col2+2)-col3*sin(col4-3))
OK, are you aware of any method of calculating a running total column calculated from either a formula column or from a query within the mysql that works within the wpdatatables environment?
When I run the following mysql query in Workbench it returns the desired result (see attachment).
set @csum := 0;
select condofee_date as Date, condofee_description as Description, condofee_amount as Amount, (@csum := @csum + condofee_amount) as Balance
FROM
condominium_fees
WHERE
apartments_apartment_id = 1
ORDER BY condofee_date;set @csum := 0;
If I run it on your plug in I get;
cannot calculate position of @csum := 0 @csum := 0 within @csum := 0; select condofee_date as Date, condofee_description as Description, condofee_amount as Amount, (@csum := @csum + condofee_amount) as Balance FROM condominium_fees WHERE apartments_apartment_id = 1 ORDER BY condofee_date;set @csum := 0;
Am I using the wrong syntax for set @csum := 0 ?
Thanks
Correct attachment here, ignore the previous one
Thanks
Hello Mark
Unfortunately, using variables ( @ ), stored procedures and nested queries is not supported, but you can prepare a MySQL view (which will return the data you need); call it “view1” for example, and then build a wpDataTable based on a simple query like “SELECT * FROM view1”.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
Thanks Aleksandar
I'm pretty sure mysql doesn't allow variables in a view either. Is there a way I can display a running balance calculated from the previous 2 columns on each row in wpdataTables?
Thanks
Mark
Hello Mark
I believe you can add a Formula Column, where you can choose previous columns to be used in a formula.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
Thanks again
I had looked at this but couldn't see a way of creating a formula that references a cell in the previous row? Do you have an example of using the formula column to create a running total type arrangement?
Hello again Mark
You can't choose a specific cell, but when creating a Formula Column, you can include (select columns from the modal) the column and use it for the formula, so like: col1*((col2+2)-col3*sin(col4-3))
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
Thanks again Aleksandar
I was aware of the ability to reference different columns, can I reference different rows (necessary for a running total column)?
Hello again Mark
Unfortunately, no. Only columns can be used in formula columns.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
OK, are you aware of any method of calculating a running total column calculated from either a formula column or from a query within the mysql that works within the wpdatatables environment?
Hi again Mark
I'm sorry, but I'm not aware of anything like that. I'm sure you'll be able to find some useful advice on stackoverflow, though.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
OK, I moved hosting to a platform that had a more recent version of PHP (7.4) and used a
SUM...OVER (PARTITION BY) as part of the SELECT query which has worked.
Hi Mark
I'm glad to hear that.
If you have any further questions or issues, please feel free to open a new ticket, and we'll gladly help.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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