Forum Discussion

Craigc3814's avatar
Craigc3814
Regular Visitor
3 years ago
Solved

If stops at 3 else's?

I just learned, unfortunatley the hard way that after the 3rd IF this formula quits working. I believe Switch is the correct way to go? But I am unsure how to loop in Lookupvalue due to lack of examples found while researching. 

 

As menitoned the first 3 IF's work then apparently PowerBI does not let you do anymore?

 

Fy22 = IF(Construction[Cashflow Tpye]="Back-Loaded",LOOKUPVALUE(Curves[Back Loaded Current],Curves[Percent Complete],Construction[FY22%Comp]),
IF(Construction[Cashflow Tpye]="Trapezoid",LOOKUPVALUE(Curves[Trapezoid Current],Curves[Percent Complete],Construction[FY22%Comp]),
IF(Construction[Cashflow Tpye]="Slow",LOOKUPVALUE(Curves[Slow Curve Current],Curves[Percent Complete],Construction[FY22%Comp],
if(Construction[Cashflow Tpye]="Front-Loaded",LOOKUPVALUE(Curves[Front Loaded Current],Curves[Percent Complete],Construction[FY22%Comp],
if(Construction[Cashflow Tpye]="Linear",Construction[FY22%Comp],0)))))))
  • Craigc3814 

    IF can go deeper than 3, you are missing some closing ) on some LOOKUPVALUE lines.

    That being said, SWITCH is the way to go and AlB gave you the solution for that.

     

7 Replies

  • Craigc3814 

    IF can go deeper than 3, you are missing some closing ) on some LOOKUPVALUE lines.

    That being said, SWITCH is the way to go and AlB gave you the solution for that.

     

  • AlB's avatar
    AlB
    Icon for Community Champion rankCommunity Champion

    Hi Craigc3814 

    I do NOT believe IF fails after three nested instances. There must be something else going on. In any case, if you want that code with SWITCH() :

     

     

    Fy22 =
    SWITCH (
        Construction[Cashflow Type],
        "Back-Loaded",
            LOOKUPVALUE (
                Curves[Back Loaded Current],
                Curves[Percent Complete], Construction[FY22%Comp]
            ),
        "Trapezoid",
            LOOKUPVALUE (
                Curves[Trapezoid Current],
                Curves[Percent Complete], Construction[FY22%Comp]
            ),
        "Slow",
            LOOKUPVALUE (
                Curves[Slow Curve Current],
                Curves[Percent Complete], Construction[FY22%Comp]
            ),
        "Front-Loaded",
            LOOKUPVALUE (
                Curves[Front Loaded Current],
                Curves[Percent Complete], Construction[FY22%Comp]
            ),
        "Linear", Construction[FY22%Comp],
        0
    )
    

     

     

     

    Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    No, you can use many If's as you want. I use a query with 15 to 20 If's sequentially. Maybe your logic is stopping before for its constructions?

    • Craigc3814's avatar
      Craigc3814
      Regular Visitor

      From what I read if you are using Direct Query mode there is a limit of 3 (found in another forum answer) but in import mode there is no limit. I am assuming that is correct because my IF statement stops working at 3

  • Yep, SWITCH would be the way to do it.  The formula from AlB  shows you how that would work.