Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
24 | |
9 | |
7 | |
6 | |
6 |
User | Count |
---|---|
29 | |
11 | |
11 | |
10 | |
6 |