Forum Discussion

siyuri's avatar
siyuri
Frequent Visitor
3 years ago
Solved

Convert SQL LIKE "__1__" to DAX

Hello! Need your help 🙂

How do I write this sql expression:

LIKE "__1__" in DAX?  

I'd Use MID(3,1) = 1, but I need exact two any characters after "1" as well and mid works from the left only?

Thanks for help!

  • Hi siyuri ,

     

    I would do the following:

    • find the position of "1"
    • subtract 2 from the position of 1 as my starting point for MID
    • then use 5 for the number of characters to extract two characters before and after "1" with "1" included in 5

    So in DAX, I'd use this formula

     

    =
    VAR PositionOf1 =
        FIND ( "1", 'Table'[Column], 1, BLANK () )
    RETURN
        MID ( 'Table'[Column], PositionOf1 - 2, 5 )
    

     

2 Replies

  • Hi siyuri ,

     

    I would do the following:

    • find the position of "1"
    • subtract 2 from the position of 1 as my starting point for MID
    • then use 5 for the number of characters to extract two characters before and after "1" with "1" included in 5

    So in DAX, I'd use this formula

     

    =
    VAR PositionOf1 =
        FIND ( "1", 'Table'[Column], 1, BLANK () )
    RETURN
        MID ( 'Table'[Column], PositionOf1 - 2, 5 )
    

     

    • siyuri's avatar
      siyuri
      Frequent Visitor

      wow...so there is really no straight forward way... Thank you for this solution!