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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Retrieve a value using a criteria on row and another on column

Hello,

 

here I come again with a complex DAX formula I need help with.

I have a source table like this : 

 

TABLE1

James_C_0-1652191166445.png

 

And I need to get into TABLE2 which already exists the data like follows : 

 

TABLE2

James_C_1-1652191209082.png

 

So I need a formula to put in "[TABLE2]Data column" which will go fetch the data filtering the row on the Name, and then filtering the column depending on the Q. Can someone help me figure out this formula ?

 

Regards

3 ACCEPTED SOLUTIONS
rohit_singh
Solution Sage
Solution Sage

Hi @Anonymous ,

Based on what I can understand by looking at your tables, table 2 looks like an unpivoted version of table 1. 
Would it suit you if you performed an unpivot operation on Table 1 in power query. ? You'd get the values you need instantly

rohit_singh_0-1652192098191.png

Please mark this answer as the solution if it resolves your issue.

Kind regards,

Rohit

View solution in original post

Hi @Anonymous ,

Try this 

Table =

UNION(
SELECTCOLUMNS(Questions_base,"Name",[Name],"Q's","Q1","Answers",Questions_base[Q1]),
SELECTCOLUMNS(Questions_base,"Name",[Name],"Q's","Q2","Answers",Questions_base[Q2]),
SELECTCOLUMNS(Questions_base,"Name",[Name],"Q's","Q3","Answers",Questions_base[Q3]),
SELECTCOLUMNS(Questions_base,"Name",[Name],"Q's","Q4","Answers",Questions_base[Q4])

)
rohit_singh_0-1652193949362.png


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos!

Kind regards,

Rohit

View solution in original post

Hi @Anonymous ,

Yes. You will use this new table as a lookup table to fetch values. This can be done as follows :

1. In the new table, create a new column using a combination of the name and q's fields 

rohit_singh_0-1652194924584.png

2. Perform the same step on youir Table 2

rohit_singh_1-1652195011747.png

3. Go to 'Manage relationships' and create a link between the new table and Table 2 using the combination key as the join.

rohit_singh_2-1652195069063.png


4. Finally, go to Table 2, add a new column using the 'Related' function. This will lookup values from the new table and add them to Table 2

rohit_singh_3-1652195154940.png

 

View solution in original post

10 REPLIES 10
negi007
Community Champion
Community Champion

@Anonymous  you can use unpivot table option in the power query window that will tranform your first table in the same format that you have in the second table. then you can merge table1 and table2. You wont need to write complex dax code.

 

go to your powerquery window, select all the columns (Q1 to Q4) and then unpivot them

 

once you have both tables in the same format. then you can use merge queries option to merge both the tables. you select both tables and then select merge queries. this all is possible in the power query window




Did I answer your question? Mark my post as a solution!
Appreciate your Kudos



Proud to be a Super User!


Follow me on linkedin

Anonymous
Not applicable

I need to do it with DAX as the Q columns already are calculated columns in DAX

rohit_singh
Solution Sage
Solution Sage

Hi @Anonymous ,

Based on what I can understand by looking at your tables, table 2 looks like an unpivoted version of table 1. 
Would it suit you if you performed an unpivot operation on Table 1 in power query. ? You'd get the values you need instantly

rohit_singh_0-1652192098191.png

Please mark this answer as the solution if it resolves your issue.

Kind regards,

Rohit

Anonymous
Not applicable

I need it to do it with dax as the Q columns already are calculated columns in DAX

@Anonymous though not recommended to use dax to unpivot but you can try below link. similar problem was solved there as well

 

powerbi - Is it possible to unpivot in Power BI using DAX? - Stack Overflow

 




Did I answer your question? Mark my post as a solution!
Appreciate your Kudos



Proud to be a Super User!


Follow me on linkedin

Anonymous
Not applicable

Well can we filter tables not only in rows but also columns ? I struggle to put the DAX code but I can do it easily in VBA

Hi @Anonymous ,

Try this 

Table =

UNION(
SELECTCOLUMNS(Questions_base,"Name",[Name],"Q's","Q1","Answers",Questions_base[Q1]),
SELECTCOLUMNS(Questions_base,"Name",[Name],"Q's","Q2","Answers",Questions_base[Q2]),
SELECTCOLUMNS(Questions_base,"Name",[Name],"Q's","Q3","Answers",Questions_base[Q3]),
SELECTCOLUMNS(Questions_base,"Name",[Name],"Q's","Q4","Answers",Questions_base[Q4])

)
rohit_singh_0-1652193949362.png


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos!

Kind regards,

Rohit

Anonymous
Not applicable

This creates a new table ? What I am looking for is a formula to put in the calculated column "Data column". I have other columns before I need to keep

Hi @Anonymous ,

Yes. You will use this new table as a lookup table to fetch values. This can be done as follows :

1. In the new table, create a new column using a combination of the name and q's fields 

rohit_singh_0-1652194924584.png

2. Perform the same step on youir Table 2

rohit_singh_1-1652195011747.png

3. Go to 'Manage relationships' and create a link between the new table and Table 2 using the combination key as the join.

rohit_singh_2-1652195069063.png


4. Finally, go to Table 2, add a new column using the 'Related' function. This will lookup values from the new table and add them to Table 2

rohit_singh_3-1652195154940.png

 

Anonymous
Not applicable

This worked perfectly. Thanks a lot !!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.