Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

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! 

2 ACCEPTED SOLUTIONS
Vvelarde
Community Champion
Community Champion

Helllo @Anonymous

 

try with:

 

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




Lima - Peru

View solution in original post

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.Smiley Happy

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

Regards

View solution in original post

4 REPLIES 4
alanhodgson
Solution Supplier
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
Not applicable

Alan, can I assign this to a measure? 

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.Smiley Happy

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

Regards

Vvelarde
Community Champion
Community Champion

Helllo @Anonymous

 

try with:

 

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




Lima - Peru

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.