• # How to draw the difference of kWh daily in weekly basis easily in DGLux

I got a kWh data point which is accumulated value. Can I draw a weekly graph that shows the difference of min/max or start/end value everyday in a week easily in DGLux ?

Here is the script used to calculate the differences in the data values:

``````if (numericRows[row-1].value &gt; 0)
{
if ((numericRows[row].value-numericRows[row-1].value) &lt; 999999999)
{
return ((numericRows[row].value-numericRows[row-1].value));
}
else
{
return 0;
}
}
else
{
return 0;
}
``````

However, the first value is always 0. When I display daily KWH of a week in the chart, the first day gets none. Others are all right. Any idea how to fix this ?

• Off hand I can't write the script exactly as it would need to be but you could modify it to handle the first or last row in the table differently. I'm pretty sure that would work if you can figure out the script. If not I'll play around with it.

Joel.

• I have the same question as Joe asked. Is there a way to specify which rows in the generated column to show in the column chart? If so the first row can be ignored to solve this problem. Thank you!

• great thanks to Joel.

• Hi Joel,

To extend this further, how can we chart both the current and previous week as comparison on the same chart?

BR,
Ricardo

• @Pine said:

I have the same question as Joe asked. Is there a way to specify which rows in the generated column to show in the column chart? If so the first row can be ignored to solve this problem. Thank you!

This can be achieved with a Data Filter (just called a 'Filter'). Bind the source table to the Data Filter input, filter on the condition "row > 0", and chart the output table.

• @ricardo said:

Hi Joel,

To extend this further, how can we chart both the current and previous week as comparison on the same chart?

BR,
Ricardo

This would have to be done with two history queries, as well as some control over the dates the tables will query.

We'll need a script widget with two string fields, to get our date ranges. Mine will be called "currWeek" and "pastWeek"

``````var now = new Date();
var weekAgo = new Date(now.getTime() - 7*24*60*60*1000);
var twoAgo = new Date(now.getTime() - 2*8*24*60*60*1000);

currWeek = weekAgo.getFullYear() + "/"+ (weekAgo.getMonth()+1) + "/" + weekAgo.getDate() + "T00:00:00-" + now.getFullYear() + "/" + (now.getMonth()+1) + "/" + now.getDate() + "T23:59:59";
pastWeek = twoAgo.getFullYear() + "/"+ (twoAgo.getMonth()+1) + "/" + twoAgo.getDate() + "T00:00:00-" + weekAgo.getFullYear() + "/" + (weekAgo.getMonth()+1) + "/" + weekAgo.getDate() + "T00:00:00";
``````

and bind those two date ranges into our table query. Perform Joel's steps to get the kWh difference. Now we're going to drag both series onto the chart, and click the 'use existing axis' check marks for the second series. We'll still have an extra axis (either above or below the chart area), but it should group the data correctly because it'll be the same number of points over the same size of interval. We can either disable the visibility of the second axis (two weeks to one week ago), or not, whichever meets your data displaying needs! Be sure to set your data interval to 1 day.

Notice that both ranges are effectively 8 days. This permits the first row to be zero, and we can pass it through a data filter as described in my previous post to get rid of that first data point.

• Hi Pine,

I am still kind of lost from your instruction above. Can you put this in a quick video?

Many thanks,
Ricardo

Posts 11Views 3367