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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
wokka
Helper IV
Helper IV

Trying to select one columns value based on another column value in same table

Hi

 

I'm very used to working with SQL Server, and I am trying to return the values of one column on a powerbi table based on text values of another column in the same table  , e.g.

 

select column1 from table1 where column2 = 'fgh'

 

Ive tried the following, but with no success :

 

Output = SELECTEDVALUE ( 'Table1'[column1], 'Table1','Table1'[column2] = "fgh")

 

Return 

    Output

 

Any help appreciated. DAX seems to be a very different world......

 

Thanks in advance.

 

1 ACCEPTED SOLUTION

Hi Jihwan_Kim

 

Thank you !  

 

Adding EVALUATE did the trick and the code below now executes from DAX Query View inside the powerbi file. It will select the rows in [column1] where the value in [column2] has the text value of  "fgh"  .

 

EVALUATE
CALCULATETABLE (
SELECTCOLUMNS ( Table1, Table1[column1] ),  Table1[column2] = "fgh"
)

 

wokka_0-1733207157599.png

 

 

I investigated further on how to create a temp table ( dynamic table ) using the same code. 

To do this I opened up Table View, pasted in the following and clicked the green tick ( note that the EVALUATE function is removed for this step ) :

 

Temp_Table1 =
CALCULATETABLE (
SELECTCOLUMNS ( Table1,  "Test_Column1",  Table1[column1] ),  Table1[column2] = "fgh"
)
 
wokka_1-1733206902664.png

 

This then creates a temp/dynamic table called Temp_table1 with column called "Test_Column1" you should see appear in thepowerbi  Data  pane. 
 
wokka_2-1733206932295.png
 
To confirm everything was all working, I then went to the Report View in powerbi, found the Temp_Table1 and dragged the Test_Column1 into the report area, and it accurately showed the contents of the column as expected.
 
 
Kudos for this.
 
 
 ------------------------
Subject :    Trying to select one columns value based on another column value in same table
 
Keywords   DAX  powerbi temp table dynamic table column value select into 

View solution in original post

9 REPLIES 9
FreemanZ
Super User
Super User

hi @wokka ,

 

not sure if i fully get you, try to create a calculated table like:

 

Calculated Table =
CALCULATETABLE(
VALUES('Table1'[column1])
FILTER(Table1','Table1'[column2] = "fgh")
)

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I assume your expected result is table.

If it is, please try something like below.

Please check the below picture and the attached pbix file.

 

Table1

Jihwan_Kim_1-1733117303982.png

 

 

SELECTCOLUMNS function (DAX) - DAX | Microsoft Learn

 

expected result table = 
CALCULATETABLE (
    SELECTCOLUMNS ( Table1, Table1[column1] ),
    Table1[column2] = "fgh"
)
 

 

Jihwan_Kim_0-1733117249485.png

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi Jihwan_kim and everyone,

 

So i had a look at the pbix file, thank you. 

If you go into the DAX query view, and run EVALUATE TOPN(100, 'Table1')   you see the contents of Table1 listed OK. 

DAX Query Editor can see Table 1 and list its contents just fine.

 

Assumption - I can run the below code in DAX Query Editor in the pbix file to generate the temporary table called expectedresulttable ( so I dont overwrite the existing table "expected result table")  

 

expectedresulttable =

CALCULATETABLE (
    SELECTCOLUMNS ( Table1, Table1[column1] ),
    Table1[column2] = "fgh"
 
And every single time I run it, I get this error:
 

Query (3, 1) The syntax for 'CALCULATETABLE' is incorrect. ( expectedresulttable = CALCULATETABLE ( SELECTCOLUMNS ( Table1, Table1[column1] ), Table1[column2] = "fgh" )).

wokka_2-1733140426319.png

 


 

Is this expected behaviour?

 

Can you please explain where / how eactly did you run the code ( above ) to generate the expected result table - which screen etc did you use please? Maybe I have missed something?

 

I need to get this running for work, so any help appreciated.

 

Thank you in advance.

Hi,

In Dax Query View, I think you missed EVALUATE statement.

 

EVALUATE keyword (DAX) - DAX | Microsoft Learn

 

Please try something like,

 

 

EVALUATE
CALCULATETABLE (
    SELECTCOLUMNS ( Table1, Table1[column1] ),
    Table1[column2] = "fgh"
)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi Jihwan_Kim

 

Thank you !  

 

Adding EVALUATE did the trick and the code below now executes from DAX Query View inside the powerbi file. It will select the rows in [column1] where the value in [column2] has the text value of  "fgh"  .

 

EVALUATE
CALCULATETABLE (
SELECTCOLUMNS ( Table1, Table1[column1] ),  Table1[column2] = "fgh"
)

 

wokka_0-1733207157599.png

 

 

I investigated further on how to create a temp table ( dynamic table ) using the same code. 

To do this I opened up Table View, pasted in the following and clicked the green tick ( note that the EVALUATE function is removed for this step ) :

 

Temp_Table1 =
CALCULATETABLE (
SELECTCOLUMNS ( Table1,  "Test_Column1",  Table1[column1] ),  Table1[column2] = "fgh"
)
 
wokka_1-1733206902664.png

 

This then creates a temp/dynamic table called Temp_table1 with column called "Test_Column1" you should see appear in thepowerbi  Data  pane. 
 
wokka_2-1733206932295.png
 
To confirm everything was all working, I then went to the Report View in powerbi, found the Temp_Table1 and dragged the Test_Column1 into the report area, and it accurately showed the contents of the column as expected.
 
 
Kudos for this.
 
 
 ------------------------
Subject :    Trying to select one columns value based on another column value in same table
 
Keywords   DAX  powerbi temp table dynamic table column value select into 
Poojara_D12
Super User
Super User

Hi @wokka 

Try using the below dax:

Output = 
CALCULATE(
    SELECTEDVALUE('Table1'[column1]),
    'Table1'[column2] = "fgh"
)

This will return the value of column1 where column2 = "fgh". If there are multiple matches, SELECTEDVALUE will return blank. Use CONCATENATEX if you expect multiple results.

 

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Please Subscribe my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS 

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

Hi

 

Thank you, although it says the calculate syntax is incorrect?

Hi @wokka 

apologise for that, can you please try this:
Output =
CALCULATE(
SELECTEDVALUE('Table1'[column1]),
FILTER('Table1', 'Table1'[column2] = "fgh")
)

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Please Subscribe my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

Hi

 

Sorry, still gives syntax error. 

 

Below is direct copy and paste of all the code , from within DAX query view exactly as it appears in my desktop powerbi :

 

 

Output =
    CALCULATE(  
               SELECTEDVALUE('Table1'[column1]),
               FILTER('Table1', 'Table1'[column2] = "fgh")
    )
 
 
Thanks for your help so far. 
 

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.