Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hello,
I wonder if there is a way in PowerBI to look up values by searching column names to return results in the matching column.
For example:
TB1:
| ID | Year |
1 | Year-1 |
| 1 | Year-2 |
| 2 | Year 0 |
| 3 | Year-1 |
TB2:
| ID | Year 0 | Year-1 | Year-2 |
| 1 | 66 | 68 | 21 |
| 2 | 35 | 59 | 54 |
| 3 | 47 | 78 | 87 |
Desired results:
| ID | Year | Qty |
| 1 | Year-1 | 68 |
| 1 | Year-2 | 21 |
| 2 | Year 0 | 35 |
| 3 | Year-1 | 78 |
Any suggestions would be appreciated!
Solved! Go to Solution.
Hi, @acao-96
If there are not many values in the year field, you can create a calculated column in TB1 as below:
Calculated column:
Dax Qty =
SWITCH (
Table1[Year],
"Year 0", LOOKUPVALUE ( Table2[Year 0], Table2[ID], Table1[ID] ),
"Year-1", LOOKUPVALUE ( Table2[Year-1], Table2[ID], Table1[ID] ),
"Year-2", LOOKUPVALUE ( Table2[Year-2], Table2[ID], Table1[ID] )
)
result:
Best Regards,
Community Support Team _ Eason
Hi, @acao-96
If there are not many values in the year field, you can create a calculated column in TB1 as below:
Calculated column:
Dax Qty =
SWITCH (
Table1[Year],
"Year 0", LOOKUPVALUE ( Table2[Year 0], Table2[ID], Table1[ID] ),
"Year-1", LOOKUPVALUE ( Table2[Year-1], Table2[ID], Table1[ID] ),
"Year-2", LOOKUPVALUE ( Table2[Year-2], Table2[ID], Table1[ID] )
)
result:
Best Regards,
Community Support Team _ Eason
@acao-96
UnPivot feature in Power Query to convert the columns for years in the TB2 table into rows then you can simplky merge or use DAX to calculate the results.
Video: https://www.youtube.com/watch?v=Vff2kRBM95o
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Thank you for your response! I was aware of the Unpivot method but I was wondering if there was a direct way to get that column in Dax instead of having to unpivot the TB2 first and then merge to get the results.
@acao-96
Check if this could help:
https://www.youtube.com/watch?v=9Xv8COs59tc
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 8 | |
| 7 | |
| 6 | |
| 5 | |
| 4 |
| User | Count |
|---|---|
| 25 | |
| 9 | |
| 8 | |
| 8 | |
| 8 |