Error in Power Query Formula

Fady Abdel Massih 20 Reputation points
2023-10-04T12:08:41.54+00:00

I have encountered a "Token Literal Expected" error in the second "if" of this formula. The formula is:


D4= 0.035,

D5= 0.05,

D6= 0.07,

E4= 1,

E5= 0.9,

E6= 0.8,

Result =

if((1-(1-if[#"% CR"]<=D4 then 1 else if [#"% CR"]<=D5 then (1-([#"% CR"]-D4)/((D5-D4)/(E4-E5))) else if [#"% CR"]<=D6 then (E5-([#"% CR"]-D5)/((D6-D5)/(E5-E6)) else 0)*2))=-1 then 0 else (1-(1-if [#"% CR"]<=D4 then E4 else if [#"% CR"]<=D5 then (E4 -([#"% CR"]-D4)/((D5-D4)/(E4-E5)) else if[#"% CR"]<=D6 then E5-([#"% CR"]-D5)/((D6-D5)/(E5-E6)) else 0)*2)))

in

Microsoft 365 and Office Development Other
Microsoft 365 and Office Install, redeem, activate For business Windows
0 comments No comments
{count} votes

Accepted answer
  1. gekka 12,206 Reputation points MVP Volunteer Moderator
    2023-10-04T14:12:03.11+00:00

    Your code does not correctly match the left and right paren.

    Correcting the code to what I assume is the correct code would look like below.

    QnA1381582

    let
    D4= 0.035,
    D5= 0.05,
    D6= 0.07,
    E4= 1,
    E5= 0.9,
    E6= 0.8,
    Result =
    if  (   
            (1- 
                (1- 
                    (if [#"% CR"]<=D4 
                    then 
                        1 
                    else 
                        if [#"% CR"]<=D5 
                        then
                            (1-
                                ([#"% CR"]-D4)
                                / 
                                ((D5-D4)/(E4-E5))
                            )
                        else 
                            if [#"% CR"]<=D6 
                            then 
                                (E5-
                                    ([#"% CR"]-D5)
                                    /
                                    ((D6-D5)/(E5-E6))
                                )
                            else
                                0
                    )*2
                )
            ) =-1
        ) 
    then 
        0 
    else 
        (1- 
            (1-
                (if [#"% CR"]<=D4 
                then 
                    E4 
                else 
                    if [#"% CR"]<=D5 
                    then
                        (E4 -
                            ([#"% CR"]-D4)
                            /
                            ((D5-D4)/(E4-E5))
                        )
                    else 
                        if [#"% CR"]<=D6 
                        then 
                            E5-
                                ([#"% CR"]-D5)
                                /
                                ((D6-D5)/(E5-E6)) 
                        else 0
                )*2
            )
        )
    in
        Result
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.