I need help with an above() formula and most probably, the problem is the recursive type of calculation, why I fail.
I want to visualize the charging/capacity status of a battery, connected to my photovoltaic panel.
Assume, at a given point in TIME, I have some power CONSUMPTION and some power PRODUCTION.
Whenever PRODUCTION>CONSUMPTION, the battery is charged.
As soon as the battery CAPACITY is reached, there is no more charging and energy is lost.
Whenever PRODUCTION<CONSUMPTION, the battery is decharged, until it reaches 0.
As soon as 0 is reached, I need power from the grid.
The following formula is a good start, but it fails to give a correct development of the battery.
This is, why so far I did not even reflect the frame conditions no negative value and no value above CAPACITY. I would just be happy to see the values change 🙂
measure Battery status defined as
CAPACITY + (PRODUCTION-CONSUMPTION),
above(total CAPACITY+ PRODUCTION-CONSUMPTION) + PRODUCTION-CONSUMPTION
Any idea how to create a measure that gives the battery status over time?
The resulting table may look like this , if we start at midnight with a full battery, over night battery is decharged and with rising sun until noon it starts charging
The EXCEL formula for the measure below is from the 2nd line
=IF( E2+C3-D3>B3; B3;
Hi, mabye adding a rangesum and the additional parameteres of above to include all above rows, something like:
Rangesum(above(total CAPACITY+PRODUCTION-CONSUMPTION,0, RowNo(TOTAL)))
Maybe capacity will go outside the rangesum to only count it once, but the general idea is to include the above in a rangesum to sum all rown since the current (the '0' parameter') to all above (Rowno(TOTAL) tries to do that)
rangesum works indeed, but it does only calculate the total aggregation. But I must be able to use the value above to start from and decide if the max CAPACITY is already reached. In that case, the aggregation cannot continue. The battery is simply full.
Maybe doing this in script, you can do a sorted load and have a field With CurrentCapacity already loaded.
In script will be easier to limit the capacity, with something like
If(Peek(CurrentCapacity)+Production-Consumption>=MaxCapacity ,MaxCapacity ,Peek(CurrentCapacity)+Production-Consumption ) as CurrentCapacity
That looks great to me. Allowing for no negative current capacity and changing the phrasing a bit:
* Rangesum rather than plus minus to avoid nulls breaking the math
* RangeMin and RangeMax rather than restating the formula in if statements
I forgot to say that it must be calculated dynamically in a table in the visualisation as there are some variable values to be included in the formula, that can be defined by the user
Rangesum(CAPACITY,above(total PRODUCTION-CONSUMPTION,0, RowNo(TOTAL)))
Since Capacity repeats for each row, we can add it externally rather than within the total, which prevents messing things up.
That said, getting this to behave correctly with a cap of CAPACITY and a floor of 0 might get tricky, but this should work for a straight running total and you can hopefully work your conditions from there.
As for CAPACITY, it is right. Actually in my final model it is not a dimension but a variable, set by the user via an input box/slider.
Unfortunately rangesum does not help. The rangesum itself is an easy total aggregation. But the tricky part is that the aggregation must stop once CAPACITY is reached or we are below 0. And here, we get the recursive definition that is not allowed in above()
Maybe someone has an idea, how to solve the recursive limitation problem?
Meanwhile I found a way to create the table with recursive measures using above() and Column().
This is the resulting Table, the first 5 columns are just repeating the excel, specifically to get column (measure) with the expected result. I used only TIME as dimension and all others as measures to make ranges and above easier. This is why the counting starts with 1 on column (capacity).
This is the resulting table (xls enclosed below):
|(CAPACITY)||(PRODUCTION)||(CONSUMPTION)||(measure)||PRODUCTION-CONSUMPTION||end capacity||start capacity||grid power need|
And this are the measures (BatteryCapacity is a variable, currently set to 12 to match the excel table)
column (6) end capacity
column(7) start capacity
column(8) grid power need (means if Battery is empty and PRODUCTION<CONSUMPTION, we need power from the grid)
=0 and PRODUCTION-CONSUMPTION<0 ,-(PRODUCTION-CONSUMPTION),0)
I tried to eliminate the "column()" referrence as much as possible but in column(7) there remains that recursive definition with above.
So far so good, BUT...
How can we now put the sum over column(8) into a KPI visual? We get it in the table easily as column sum. But in an KPI field I would assume we need some
Is this possible somehow?