Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

SQL to DAX

Hello everyone.

 

I need to extract the single value of a cell from a table and showcase it. My initial thoughts are to write a DAX query and assign it to a measure. 

 

However, I'm not sure of how to write the DAX query. The query in SQL will look like this - 

 

SELECT <COL1> FROM <TABLENAME> WHERE <COL2> = 'x' AND <COL3> = 'y' ;

 

Can someone help me convert this to DAX? 

 

Thanks in advance! 

  • Helllo Anonymous

     

    try with:

     

    Measure= Calculate(Values(Table[Col1]),Filter(Table,Table[Col2]="x" && Table[Col3]="y"))

  • Hi Anonymous,

     

    Have you tried the measure provided by Vvelarde? It should work.

     

    In addition, just in case there may be multiple values returned with the condition of the filter, we can add FIRSTNONBLANK Function (DAX) within the measure in this scenario.:smileyhappy:

    Measure =
    CALCULATE (
        FIRSTNONBLANK ( VALUES ( 'TableName'[Col1] ), 1 ),
        FILTER ( 'TableName', 'TableName'[Col2] = "x" && 'TableName'[Col3] = "y" )
    )

    Regards

4 Replies

  • Vvelarde's avatar
    Vvelarde
    Community Champion

    Helllo Anonymous

     

    try with:

     

    Measure= Calculate(Values(Table[Col1]),Filter(Table,Table[Col2]="x" && Table[Col3]="y"))

  • alanhodgson's avatar
    alanhodgson
    Solution Supplier

    Hello Anonymous,

     

    You can use the FILTER function to achieve this. See below:

     

    EVALUATE
    FILTER( VALUES('TableName'[Col1], AND('TableName'[Col2] = "x", 'TableName'[Col3] = "y" ))

     Hope this helps,

     

    Alan

    • Anonymous's avatar
      Anonymous
      Not applicable

      Alan, can I assign this to a measure? 

      • v-ljerr-msft's avatar
        v-ljerr-msft
        Microsoft Employee

        Hi Anonymous,

         

        Have you tried the measure provided by Vvelarde? It should work.

         

        In addition, just in case there may be multiple values returned with the condition of the filter, we can add FIRSTNONBLANK Function (DAX) within the measure in this scenario.:smileyhappy:

        Measure =
        CALCULATE (
            FIRSTNONBLANK ( VALUES ( 'TableName'[Col1] ), 1 ),
            FILTER ( 'TableName', 'TableName'[Col2] = "x" && 'TableName'[Col3] = "y" )
        )

        Regards