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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
ARomera
Regular Visitor

Help with Running Calculation - DAX

Hi everyone,

I'm hoping someone can help me with a running calculation that I’ve been struggling to get working.

 

I’ve attached a link to the https://docs.google.com/spreadsheets/d/1yNDOkxsRPuLA_zxsdgapJm2jMqog9Fnf/edit?usp=drive_link&ouid=10... spreadsheet with the relevant data, and below is a snapshot of what I’m trying to achieve.

 

We work with a 13-period forecast, and in the data, I have a column for periods 1 to 13 and a column for EI $ which is calculated as EI % times the period salary+period bonus. However, there is a cap for the total EI amount for the year, which is shown in the EI Max Amount.

 

In the example provided, the EI $ would nearly reach the max by period 3, and in period 4, the amount would only be the remaining balance to meet the yearly cap. After the total EI cap is reached, all subsequent periods should display zero to ensure the forecast is accurate.

 

I really appreciate any help you can provide in getting this to work properly.

 

Thank you in advance!

 

DepartmentType of EmploymentSharedLevelBonus %StatusExpenseAnnual SalaryAdjusted SalaryPeriodTogglePeriod SalaryTeam FactorIndivial FactorPeriod BonusEI % CalculatedEI $ CalculateEI MAX Amount
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.0011$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.0021$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.0031$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.0041$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.0051$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.0061$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.0071$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.0081$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.0091$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.00101$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.00111$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.00121$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24
CustomerPermanentNo1330%ActiveCustomer$211,150.00$211,150.00131$16,242.3175.00%120.00%$4,385.422.32%$478.56$1,466.24

 

 

 

5 REPLIES 5
powerbiexpert22
Post Prodigy
Post Prodigy

Hi @ARomera 

you will have to add index column in power query

powerbiexpert22
Post Prodigy
Post Prodigy

Hi @ARomera ,

 

Please try below , please see below pbix file for your reference

https://drive.google.com/file/d/1y1rUUZ7x6P-4dn7mFib_JsVI4WNNwyrZ/view?usp=drive_link

 

runningsum =
CALCULATE(sum(Sheet1[EI $ Calculate.2]),FILTER(all(Sheet1),Sheet1[Index]<=max(Sheet1[Index])))
 
runnsum1 =
IF([runningsum]<=max(Sheet1[EI MAX Amount.2]),[runningsum],0)
 
powerbiexpert22_0-1727851247391.png

 

 

 

 

 

 

 

Hi @powerbiexpert22 ,

 

Really appreciate your help on this. 

 

I tried the formula above, but for some reason the results shows zero to me to all the rows. Please, see below. Not sure if I am doing something incorrect, here are the screenshots:

 

Do I need to include anything else?

 

Thank you,

 

 

ARomera_1-1727886367827.png

ARomera_2-1727886406073.png

 

 

 

ARomera_0-1727886243442.png

 

Hi @ARomera ,

 

I think your issue should caused by that you use ALL() in the measure. Here I suggest you to try ALLEXCEPT().

runningsum =
VAR _RunningSum =
    CALCULATE (
        SUM ( AOP[EI $ Calculate] ),
        FILTER (
            ALLEXCEPT ( AOP, AOP[Department], AOP[Type of Employment], AOP[Level] ),
            AOP[Period] <= MAX ( AOP[Period] )
        )
    )
RETURN
    IF ( _RunningSum <= MAX ( AOP[EI MAX Amount] ), _RunningSum, 0 )

Result is as below.

vrzhoumsft_0-1727940810845.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

@v-rzhou-msft , thanks for looking into it, I have used the formula above, but didnt get the results I needed. I have made few changes I and think I got some progress, however, I just cannot figure it out what I am doing wrong and why I cannot get the results calculated properly. 

 

Would you be able to help me figure it out what I am doing wrong?

 

I really appreciate your help.

 

 

 

Here is the formula I've included for the running calculation:

 

=

VAR _MaxAmount = MAX('AOP'[EI MAX Amount]) -- EI Max limit for the employee (1,466.24 annual)

VAR _RunningSum =

SUMX (

FILTER (

AOP,

AOP[Period] <= EARLIER(AOP[Period]) &&

AOP[INDEX] = EARLIER(AOP[INDEX])

),

AOP[EI $ Calculate]

)

VAR _RemainingAmount = _MaxAmount - _RunningSum -- Calculate the remaining amount before reaching the cap

RETURN

IF (

_RunningSum <= _MaxAmount,

IF (

AOP[EI $ Calculate] > _MaxAmount, -- condition to check if EI $ Calculate exceeds max amount

_MaxAmount, -- If it does, return EI Max Amount

MIN(AOP[EI $ Calculate], _RemainingAmount) -- Else, return the lesser of EI $ Calculate or the remaining cap amount

),

0 -- Return 0 if the cap is reached

 

Here is a screenshot of the table - I get the amount running, but the total doesnt match - it should be 1,466.24 as everyone will max out before YE.

 

I am also getting instances where it only calculates up to period 2 and then the total doesnt match as well.

 

ARomera_1-1727970699127.png

Here is the snapshot of the data for the above one:

ARomera_2-1727970979985.png

 

ARomera_0-1727970594688.png

 

 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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