Forum Discussion

Sparkeltje's avatar
Sparkeltje
Frequent Visitor
5 years ago
Solved

How to translate SQL to DAX &&& 'table'[PK_Inv#] like '_____'

Hello guys,   Hope you can help me, I'm looking for the dax equivelament for like in SQL, in this case I want DAX only to CALCULATE if investments are with 5 positions.  Investments = VAR F...
  • v-cazheng-msft's avatar
    5 years ago

    Hi Sparkeltje 

    You can use LEN function to get the investments with 5 positions.

     

    InvInvestments =
    
    VAR FINYEAR =
    
        SELECTEDVALUE ( 'table'[Financial_Year] )
    
    RETURN
    
        CALCULATE (
    
            SUMX (
    
                FILTER (
    
                    'table',
    
                    'table'[Source] = "PL"
    
                        && LEN ( 'table'[PK_Inv#] ) = 5
    
                        && 'table'[Type] IN { "1", "2" }
    
                ),
    
                'table'[costs]
    
            ),
    
            'table'[Financial_Year] = FINYEAR,
    
            'table'[Financial_Year]
    
    )

     

    For more details about this function, you can refer LEN.

     

    Best Regards

    Caiyun Zheng

     

    Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.