Forum Discussion

alya1's avatar
alya1
Icon for Helper V rankHelper V
2 years ago
Solved

Calculate total previous year points earned based on decimal customer length and customer type?

Hello All,   I have a table like below ID    Customer Length (yrs)    Customer Type    Benefit points per day (calculated column based on customer length and type)    111 3.1 A 10 2...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi, alya1

    Thanks for ryan_mayu's concern about this issue.

     

    I am glad to help you.

     

    According to your description, you can refer to my DAX formula New Column:

    TotalPointsLastYear =
    VAR CustomerLength = [Length (yrs)]
    VAR CustomerType = [Customer Type]
    VAR PointsPerDay =
        SWITCH (
            TRUE (),
            CustomerType = "A"
                && CustomerLength < 3, 5,
            CustomerType = "A"
                && CustomerLength >= 3, 10,
            CustomerType = "B"
                && CustomerLength < 3, 10,
            CustomerType = "B"
                && CustomerLength >= 3, 20,
            CustomerType = "C"
                && CustomerLength < 1, 10,
            CustomerType = "C"
                && CustomerLength >= 1
                && CustomerLength < 5, 20,
            CustomerType = "C"
                && CustomerLength >= 5
                && CustomerLength < 10, 30,
            CustomerType = "C"
                && CustomerLength >= 10, 40
        )
    VAR PreviousTierPoints =
        SWITCH (
            TRUE (),
            CustomerType = "A"
                && CustomerLength < 3, 5,
            CustomerType = "A"
                && CustomerLength >= 3, 5,
            CustomerType = "B"
                && CustomerLength < 3, 10,
            CustomerType = "B"
                && CustomerLength >= 3, 10,
            CustomerType = "C"
                && CustomerLength < 1, 10,
            CustomerType = "C"
                && CustomerLength >= 1
                && CustomerLength < 5, 20,
            CustomerType = "C"
                && CustomerLength >= 5
                && CustomerLength < 10, 20,
            CustomerType = "C"
                && CustomerLength >= 10, 30
        )
    VAR FractionNewTier =
        CustomerLength - FLOOR ( CustomerLength, 1 )
    VAR FractionOldTier = 1 - FractionNewTier
    RETURN
        ( FractionNewTier * 365 * PointsPerDay ) + ( FractionOldTier * 365 * PreviousTierPoints )
    


    Here are my test results:

     

     

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
    Best Regards,
    Fen Ling,
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.