I receive a daily export of data every day I load into my excel sheet via Power Query. The table of data I can't control is:
tblExport
| Name | Company | States |
|---|---|---|
| Jane Doe | ABC | AK,AL,GA,WA |
| John Smith | ACME | AK,GA,FL,WA |
I need to replace those State Abbreviations with a technology string of information for this question I'll use "Full State Name" as a substitute. So basically it checks the COMPANY field against another table as the "technology Strings" will be different for each Company per State.
So far so good, or so I thought. Then I split delimiters of tblExport.States BY "," which then I get
| Name | Company | States.1 | States.2 | States.3 | States.4 |
|---|---|---|---|---|---|
| Jane Doe | ABC | AK | AL | GA | WA |
| John Smith | ACME | AK | GA | FL | WA |
Now we reference that table that contains the Company, State, FullStateNames
tblStateNames
| COMPANY | Abbr | State Name |
|---|---|---|
| ABC | AL | AlabamaABC |
| ABC | AK | AlaskaABC |
| ACME | AK | AlaskaACME |
| ACME | GA | GeorgiaACME |
| ABC | FL | FloridaABC |
| ABC | WA | WashingtonABC |
| ACME | WA | WashingtonACME |
ST01 = Table.NestedJoin(#"Changed Type1", {"States.1", "Company"},
tblStateNames, {"Abbr", "Company"}, "tblStateNames",
JoinKind.LeftOuter),
ExpST01 = Table.ExpandTableColumn(ST01, "tblStateNames", {"State
Name"}, {"tblStateNames.State Name"}),
Which works great until I meet a condition such as Company ABC has GA in the TblExport.States, but they do not qualify for GA. So when it joins the query tblStateNames and ABC doesn't match for GA it returns a null value.
So my column output is
| Name | Company | ST01 | ST02 | ST03 | ST04 |
|---|---|---|---|---|---|
| Jane Doe | ABC | AlaskaABC | AlabamaABC | null | WashingtonABC |
| John Smith | ACME | AlaskaACME | GeorgiaACME | FloridaACME | WashingtonACME |
A couple things about this. The original TblExport is a daily intake and the people range for their states, some will have ZERO and the rest can be anywhere from 1 to 40 states. The challenge and why this is semi the issue is because I can't have any gaps in the columns. So while ST03 displays null as it should I rather have it fill ST04 into the ST03 column.
| Name | Company | ST01 | ST02 | ST03 | ST04 |
|---|---|---|---|---|---|
| Jane Doe | ABC | AlaskaABC | null | null | WashingtonABC |
| John Smith | ACME | AlaskaACME | GeorgiaACME | FloridaACME | WashingtonACME |
Now after the fact I could do a conditional IF ST02 is not equal <> null then ST02 else ST03. However in this example that null simply moves from ST03 to ST02. However, this only moves the next one down a column, so a double null will still lead to an issue.
In my very new to PQ head, I think I somehow need to validate the states in the original delimited field before doing the query lookup?
I know I've probably overly complicated things and masking the actual code for internal only reasons, takes a bit longer for me to try to explain. :)
I appreciate any input, when responding, try to keep in mind my experience level. Experience Level: I'm a Highly Functioning Idiot.
Patrick
