Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago

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=102505936425969572198&rtpof=true&sd=true 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

    • Anonymous's avatar
      Anonymous
      Not applicable

      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,

       

       

       

       

       

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous ,

         

        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.

         

        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.