I'm working with the American Community Survey in Power BI and want to replace values in every column with corresponding values in another table of response labels. For example, race is encoded as 1,2,3,4,5 but I want to replace it with Asian, Black, Native, etc according to the response labels provided.
Let's say I have the following table with three variables and peoples' responses:
variable1 | variable2 | variable3 |
---|---|---|
1 | 2 | 3 |
2 | 3 | 2 |
3 | 1 | 1 |
3 | 3 | 2 |
2 | 2 | 3 |
I am provided with this table of response keys:
VarName | ResponseKey | ResponseLabel |
---|---|---|
variable1 | 1 | blue |
variable1 | 2 | red |
variable1 | 3 | green |
variable2 | 1 | left |
variable2 | 2 | right |
variable2 | 3 | down |
variable3 | 1 | high |
variable3 | 2 | medium |
variable3 | 3 | low |
What I want is those three variables with the peoples' responses as the 'ResponseLabel' like so:
variable1 | variable2 | variable3 |
---|---|---|
blue | right | low |
red | down | medium |
green | left | high |
green | down | medium |
red | right | low |
Usually I would go one by one and replace each variable by hand but I would rather have a root canal than do that for hundred plus variables with anywhere from 2-100 responses so I imagine there is a better way to do this.
So far, I've thought about making tables for each variable and merge with the original table but that sounds like a lot as well. Then I thought maybe I should write a function to iterate across the original table and recode each column one by one. I'm also thinking there might be a way to do this in M but I'm not sure.
Do you have any ideas? Thanks!