Data is a flat normalised table:
|ID | Product selected | Product Code 1 | Product Code 2 | Product Code 3 | Cost of Product 1 | Cost of Product 2 | Cost of Product 3 | Rate of Product 1 | Rate of Product 2 | Rate of Product 3 |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|1 | ABCDEDFHIJKL | AAABBBCCCDDD | ABCDEDFHIJKL | DDDCCCBBBAAA | 995 | 495 | 0 | 4.4 | 6.3 | 7.8 |
|2 | DDDCCCBBBAAA | AAABBBCCCDDD | ABCDEDFHIJKL | DDDCCCBBBAAA | 995 | 495 | 0 | 4.4 | 6.3 | 7.8 |
What:
Using the product selected (ABCDEDFHIJKL), look across the rows to find the corresponding locations of columns with data relating to the product selected.
Desired Output:
| Product selected | Cost of Product | Rate of Product |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ABCDEDFHIJKL | 495 | 6.3 |
| DDDCCCBBBAAA | 0 | 7.8 |
To do this in R is straight forward, and i'm sure for someone more knowledgable in SQL than I, this will be easy
Either use unpivot or union or crossapply
Unpivot sample