Forum Discussion

venkb's avatar
venkb
Helper I
5 years ago
Solved

How to convert a SQL IN statement to DAX query

Hello, I am trying to convert the below SQL query to DAX but with no luck - Any help would be appreciated   Select * from A where convert(date, DateTime) in ('2020-11-05', '2020-11-06') and State...
  • amitchandak's avatar
    5 years ago

    venkb , Try 

    measure =
    var _tab = summarize(filter(A, [date]= date(2020,11,05) && [State] ="Step2" && [Status] = "Status" ), A[FileName])
    return
    calculate(countrows(A) , filter(A , [FileName] in _tab && [State] ="Step2" && [Status] = "Status" ))

     

    Or a table as 

    Table =
    var _tab = summarize(filter(A, [date]= date(2020,11,05) && [State] ="Step2" && [Status] = "Status" ), A[FileName])
    return
    calculatetable(A, filter(A , [FileName] in _tab && [State] ="Step2" && [Status] = "Status" ))

     

     

    Please provide your feedback comments and advice for new videos
    Tutorial Series Dax Vs SQL Direct Query PBI Tips
    Appreciate your Kudos.

  • Icey's avatar
    5 years ago

    Hi venkb ,

     

    Since you want to pass slicer value into your DAX expression, it is needed to create a measure like below and put it into visual filter field.

    Measure =
    VAR FileName =
        SUMMARIZE (
            FILTER (
                ALLSELECTED ( A ),
                A[Date] = SELECTEDVALUE ( SlicerTable[Date] )
                    && A[State] = "Step2"
                    && A[Status] = "Success"
            ),
            [FileName]
        )
    VAR Result =
        IF (
             (
                MAX ( A[Date] ) = SELECTEDVALUE ( SlicerTable[Date] )
                    || MAX ( A[Date] )
                        = SELECTEDVALUE ( SlicerTable[Date] ) + 1
            )
                && MAX ( A[State] ) = "Step1"
                && MAX ( A[Status] ) = "Success"
                && MAX ( A[FileName] ) IN FileName,
            1
        )
    RETURN
        Result
    

     

     

     

    Best regards

    Icey

     

    If this post helps, then consider Accepting it as the solution to help other members find it faster.