Forum Discussion

mikebi's avatar
mikebi
Helper III
2 years ago
Solved

Optimize this DAX

Hello,

Is there a way to optimize this DAX for a calculated column?

I call Lookup 3 times.  

 

 

Thank You,

Michael

Level 2 Description =
IF (
    ISBLANK (
        LOOKUPVALUE ( Input[Description], Input[Cost Center], Input[Level 2] )
    ),
    LOOKUPVALUE ( Input[Description], Input[Cost Center], Input[Level 1] ),
    LOOKUPVALUE ( Input[Description], Input[Cost Center], Input[Level 2] )
)

 

 

 

  • mikebi 

     

    try the following : 

    cc = 

    var v1 = LOOKUPVALUE ( Input[Description], Input[Cost Center], Input[Level 2] )

    var v2 = LOOKUPVALUE ( Input[Description], Input[Cost Center], Input[Level 1] )

    var v3 =     LOOKUPVALUE ( Input[Description], Input[Cost Center], Input[Level 2] )

     

    return

    switch(

    true() , 

    isblank(v1) , v2 , v3 ) 

     
     
     
    let me know if this helps.
     
     
    If my answer helped sort things out for you, i would appreciate a thumbs up πŸ‘ and mark it as the solution βœ…
    It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🀠:

2 Replies

  • Daniel29195's avatar
    Daniel29195
    Community Champion

    mikebi 

     

    try the following : 

    cc = 

    var v1 = LOOKUPVALUE ( Input[Description], Input[Cost Center], Input[Level 2] )

    var v2 = LOOKUPVALUE ( Input[Description], Input[Cost Center], Input[Level 1] )

    var v3 =     LOOKUPVALUE ( Input[Description], Input[Cost Center], Input[Level 2] )

     

    return

    switch(

    true() , 

    isblank(v1) , v2 , v3 ) 

     
     
     
    let me know if this helps.
     
     
    If my answer helped sort things out for you, i would appreciate a thumbs up πŸ‘ and mark it as the solution βœ…
    It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🀠:
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi mikebi 

     

    You can optimize your DAX by reducing the number of times is called. This can be achieved by using a variable to store the result of the first call and then reusing that variable in your statement.

     

    Please try changing dax to:

     

    Level 2 Description =
    VAR Result = LOOKUPVALUE(Input[Description], Input[Cost Center], Input[Level 2])
    RETURN
        IF(
            ISBLANK(Result),
            LOOKUPVALUE(Input[Description], Input[Cost Center], Input[Level 1]),
            Result
        )

     

    This approach can help improve performance by reducing the number of calls to the calculated column from three to a maximum of two.

     

    Regards,

    Nono Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.