I have a dataset where each customer has multiple records for different actions against their record. To be able to perform the requested analysis I need to transform this data such that each customer has a single record in the table (almost a reverse pivot). Generally customers can have up to 20 transactions. I have setup up a boring (and am sure ineffecient) script which identifies the earliest transaction (using summarisation) and then joins back to the base table ignoring this earliest record to get a new population. Then repeat this again and again. Eventually rejoin all the tables together and have a single row per customer with earliest transaction as field 1 progressing to more recent up to field 18.
The problem I am having is that occasionally there are only 17 transactions and the 18th table is empty. This is corrupting my final join which then prevents all subsequnet scripts from running. I am hoping you can point me in the direction to write a piece of script which will let me do something like the following:
1. If table 18 is populated with at least 1 record proceed with the join
2. If table 18 is empty take a different action eg Rename table 17 to 18 and insert some empty columns allowing rest of my scripts to run correctly.
Would appreciate any help you can provide.
Thanks in advance
Last seen: 2 years 2 months ago
Joined: 11/07/2019 - 10:53