hello, could you help me please, I want to add two values “BASIC SQL QUERY”, a “basic sql query” that returns a single value of electricity consumption and add the other “basic sql query” in a script, I attach the pictures, thank you very much.
Dataset=data[‘PUESTO_2_INI’].getCoreResults()
Dataset1=data['PUESTO_2_FIN'].getCoreResults()
sum = Dataset+Dataset1
data['myKey']=sum
Give my code a try, i think it will do what you want, but be sure to change it to the correct data type and appropriate column name. You can also create a new data source ‘myKey’ by changing the last line to this:
It still does not work, I want to add these two data, and then enter the summed value to the report.
At the moment of adding, I get that it is not valid to add between datasets.
I want to get the sum of "POST_INI" and "POST_END", the query "post_ini" reads the variable Amps from an old date, and the query "post_end" reads the same variable Amps with today's date, I want to add those two values by means of a script.
The query returns a single value, not a column or a row, it only returns one value.
I think this is a language/terminology problem. And the queries return a dataset not a single value.
If you want to add the values of two datasets with exactly one row and one column each then this will do it. You don’t need the for loop, based on your description, but it will work with it. You might want to use a float instead of an int.
Dataset1 = data['PUESTO_2_INI'].getCoreResults()
Dataset2 = data['PUESTO_2_FIN'].getCoreResults()
val = []
for row in range(Dataset1.getRowCount()):
val.append(Dataset2.getValueAt(row, 0) + Dataset1.getValueAt(row, 0))
data['myKey'] = system.dataset.addColumn(Dataset1, val, 'newCol', int)
Well, neither of your basic queries have any data, how are you getting any numbers at all, on your report?
What does your configuration look like?
If all you are doing is adding two values together you can do that without scripting.
This is my test report, with 3 ways of adding the values together (the script is a bit different than what i have posted, i can post the alternate version if you need).
Thank you very much I will try it.
I’m still testing and I’m using the variables that come by default in Ignition, so I can do the sum. When I can do the addition I will do it with the KWH.
If my attempt does not work, do you think you can advise me remotely? Thank you very much