Reputation: 7618
I have following ONE dataset with additional columns not mentioned for ease of reading,
Address1_PostCode Address2_PostCode
Address1_Line1 Address2_Line1
Address1_Line2 Address2_Line2
Address1_Country Address2_Country
Desired output is,
Address2_PostCode
Address2_Line1
Address2_Line2
Address2_Country
Here is what I am trying to do,
If any of Address1 field has data then overwrite Address2 fields, e.g. if Address1 only has postcode and Address2 has Country, the final result will have only postcode and country will be empty or null
If all fields of Address1 are empty then don't do anything
I already searched on my own and I can see there is functionalities like replace column to add new and replacenull function, but I am not able to understand them enough to achieve my goals
Upvotes: 2
Views: 1264
Reputation: 5594
I would suggest an alternate data model which allows you to keep your original data intact.
Add this simple code.
AddressOutputBuffer.AddRow();
AddressOutputBuffer.PersonKey = Row.PersonKey;
AddressOutputBuffer.AddressType = "Address1";
AddressOutputBuffer.AddressLine1 = Row.Address1_Line1;
... (Add the rest in here)
AddressOutputBuffer.AddRow();
AddressOutputBuffer.PersonKey = Row.PersonKey;
AddressOutputBuffer.AddressType = "Address2";
AddressOutputBuffer.AddressLine1 = Row.Address2_Line1;
... (Add the rest in here)
Write this new Person Address info to a new table (you can build whatever logic you want to the queries you write or you can create a view to handle your specific logic.)
NOTE: You may need to null handle the code above Ex:
AddressOutputBuffer.AddressLine1 = !Row.Address1_Line1_IsNull?Row.Address1_Line1:"";
Upvotes: 1
Reputation: 14189
Add a Derived Column transformation that has a new column expression with a boolean result that will check whether all Address1 fields are empty/null or not.
Add another Derived Column transformation after that one (unless you want to repeat the validation expression on each column) that checks for this bool result and reassigns the proper field from either Address1 or Address2, on each field you need.
On this last step you can either add new columns to the flow or overwrite existing ones, just make sure that you are using the ones being checked.
Upvotes: 2