Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Mauerwinkel
Regular Visitor

Running total with upper and lower limit

Hello,

I want to calculate a running total with upper and lower limit. In my example upper limit is 8000, lower is 0. The formula in excel looks like this:

=WENN(([@[Einspeisung (Wh)]]-[@[Bezug (Wh)]]+E12) < 0; 0; WENN(([@[Einspeisung (Wh)]]-[@[Bezug (Wh)]]+E12) > $G$2; $G$2; [@[Einspeisung (Wh)]]-[@[Bezug (Wh)]]+E12))      (WENN means IF)

The corresponding table:

Mauerwinkel_0-1664826194911.png

How would this formula look in DAX? Thanks for your proposals.

Holger

4 REPLIES 4
Mauerwinkel
Regular Visitor

HI, @v-easonf-msft ,

 

E12 stands for the previous cell. What I do here in Excel is building the running total bei adding the previous cell. In E2 is added E1, in E3 is added E2 and so on. This is exactly, where I have difficulties to build it in DAX, especially in combination with the IF-conditions. 

I could also add an xlsx-file here, but I'm not sure how that works. Thanks for helping me.

 

Regards Holger

Hi, @Mauerwinkel 

This kind of recursive is easy to implement in excel, but Dax is not good at handling it.

 

Best Regards,
Community Support Team _ Eason

 

I do have exactly the same issue on my desk for some months and I am unable to solve it in DAX so far. I will try to reexplain the issue and any help is highly appreciated:

 

The issue is about a battery storage for a wind power plant. We sell the energy to traders, but right now we must accept discounts, as we are not able to guarantee a predicted energy amount 24 hours in advance. There is always a difference, let's call it [delta], between the forecast and the real production. We intend to use batteries to reduce this difference. My task is to calculate the optimal size of these batteries. To do so, I must split the delta to the amount, which can be stored in the battery and the residual delta, for which we will have to pay a penalty. 

 

Example:

Let's asume the battery has a capacity of 5 and an initial state of charge [Battery_SOC] of 2,5, reflecting 50% charging. The following table shows the [Delta] between production and forecast. As long as the [Battery_SOC] is in the interval [0..5] the [Delta] is assigned to [Delta_Battery]. Any residual [Delta] is assigned to [Delta_Grid]. In consequence we get the following charging figures:

 

TimeStamp BOPTimeStamp EOPDeltaBattery_SOC_BOPBattery_SOC_EOPDelta_BatteryDelta_Grid
0:000:150,90,51,41,40,0
0:150:301,11,42,61,10,0
0:300:450,82,63,40,80,0
0:451:001,53,44,91,50,0
1:001:150,74,95,00,10,6
1:151:300,75,05,00,00,7
1:301:45-2,05,03,0-2,00,0
1:452:00-1,53,01,5-1,50,0
2:002:15-4,01,50,0-1,5-2,5
2:152:301,00,01,01,00,0

 

The calculation is easy in Excel, but given the extreme high numer of datapoints, the calculation must be performed in PowerBI (DAX or M). I am simply unable get the right code for Battery_SOC_BOP, which is always Battery_SOC_EOP from the periode before.

 

Thank you in advance for your support!!!

v-easonf-msft
Community Support
Community Support

Hi, @Mauerwinkel 

Not fully sure what you want. Can you share the expected result in excel?

Does the value in the cell E12 in the formula have any special meaning?

Please check if the following formula helps:

Result =
VAR E12 = 81
VAR a = 'Table'[Einspeisung (Wh)] - 'Table'[Bezug (Wh)] + E12
RETURN
    IF ( a < 0, 0, IF ( a > 8000, 8000 ) )

Best Regards,
Community Support Team _ Eason

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors