Forum Discussion

Avari_ya's avatar
Avari_ya
New Member
1 year ago
Solved

Help me customize the function.

Help me customize the function. There are three conditions for reaching the target - 100%, 95%, 90%. Depending on this counts the bonus 12%, 8%, 4%. But if there is no testing, then minus 5% of th...
  • DataNinja777's avatar
    1 year ago

    Hi Avari_ya ,

     

    Certainly. The issue with your original formula lies in the order and overlap of conditions inside the SWITCH(TRUE(), ...) block. In DAX, SWITCH(TRUE(), ...) evaluates each condition in order, and once it finds the first condition that evaluates to TRUE, it stops evaluating the rest. In your version, some overlapping conditions caused the function to return unintended results.

    Here is a revised version of the function that simplifies the logic, checks the percentage thresholds in descending order, and deducts 5% from the bonus if the test score is missing:

    Bonus Score Quality = 
    VAR IBOBMaxBonus = 0.12
    VAR ChatMaxBonus = 0.08
    VAR MinBonus = 0.04
    VAR Penalty = 0.05
    VAR LineType = SELECTEDVALUE(PMI_Targets_Agents[Line])
    VAR QualityScore = [Target Agent Volume Quality]
    VAR Target100 = [Target Agent Quality]
    VAR Target95 = [Target Agent Quality 0.95]
    VAR Target90 = [Target Agent Quality 0.9]
    VAR HasTest = NOT(ISBLANK([Target Agent T&D Test Score]))
    
    RETURN
    SWITCH(
        TRUE(),
        LineType = "IB" && QualityScore >= Target100, IBOBMaxBonus - IF(HasTest, 0, Penalty),
        LineType = "IB" && QualityScore >= Target95, ChatMaxBonus - IF(HasTest, 0, Penalty),
        LineType = "IB" && QualityScore >= Target90, MinBonus - IF(HasTest, 0, Penalty),
        LineType = "IB", 0,
        BLANK()
    )
    

    This version ensures that the proper bonus rate is selected based on the performance level, and it penalizes agents without test scores by reducing their bonus by 0.05. The conditions are ordered from highest to lowest target level so the logic flows correctly.

     

    Best regards,