Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

I am not Understanding How the LEN and Search function are working.

  • Anonymous -

    Maybe this explains how 11 is returned? 12 - 1 = 11

     

4 Replies

  • ChrisMendoza's avatar
    ChrisMendoza
    Icon for Resident Rockstar rankResident Rockstar

    Anonymous -

    Operator Precendence / Order of Operations seems to be messing up your calculation.

     

    You could enclose with ( ) as:

    LEN ( Customer[Customer] ) - ( SEARCH ( "(", Customer[Customer], 1, 0 ) - 1)

    or you could write two variables as:

    Column = 
    VAR lenCust = LEN ( Customer[Customer] )
    VAR searchParen = SEARCH ( "(", Customer[Customer], 1, 0 ) - 1
    
    RETURN lenCust - searchParen
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Chris,

       

      Thank you for your reply.  I know how to get the right total since 11 is the correct total.  My issue is I am not understanding how The Value of LEN('Customer'[Customer]) – SEARCH("(",'Customer'[Customer],1,0) – 1 equals 11.

       

      If the Length is 27 and the value of the Search is 14, then how is it possible that statement equals 11 instead of 13 when 27 - 14 = 13.  I'm needing someone to explain how the 11 is derived.

       

      Kind Regards,

       

      Hexagony

      • ChrisMendoza's avatar
        ChrisMendoza
        Icon for Resident Rockstar rankResident Rockstar

        Anonymous -

        Maybe this explains how 11 is returned? 12 - 1 = 11