Experts!
I'm still struggling with what types of macro to use.
I have two table I need to join. One table contains mapping logic while another table contains transactions.
Logic table
Logic ID | Region | City | Factory | Product Category | Mapping Column01 | Mapping Column02 | Mapping Column03 | Mapping Column04 |
1 | West | San Francisco | A | * | Region | City | Factory | |
2 | West | Irvine | * | * | Region | City | ||
3 | West | Los Angeles | A | X | Region | City | Factory | Product Category |
4 | East | New York | A | * | Region | City | Factory | |
5 | Central | * | * | * | Region | |||
6 | West | * | * | * | Region | |||
7 | East | * | A | * | Region | Factory | ||
8 | East | * | * | * | Region |
Transaction Table
Transaction ID | Region | City | Factory | Product Category | Amount | |
1 | West | Los Angeles | A | X | 100 | ==> should be mapped with Logic 3 and 6 |
2 | West | Oakland | B | Y | 200 | ==> should be mapped with Logic 6 |
3 | East | New York | A | X | 300 | ==> should be mapped with Logic 4 ,7 and 8 |
4 | Central | Chicago | A | X | 400 | ==> should be mapped with Logic 5 |
5 | East | Boston | A | X | 500 | ==> should be mapped with Logic 7 and 8 |
6 | West | San Francisco | A | X | 600 | ==> should be mapped with Logic 1 and 6 |
I've tried "Transpose" and "Crosstab" method and kinda figured it out.
But, I would like to know whether it can be done using a macro.
Do you have a good idea for this?
I'd really appreciate you experts' help and advice.
Ideal method that I would love to try is feeding those mapping columns into a macro so the macro knows which columns to use for joining.
Is this doable using a macro?
----------------
Thank you all for the responses. It has been a great help.
Regarding the issue that I am facing with the solution below;
Logic ID | Region | City | Factory | Product Category |
1 | West | Irvine | * | X |
If I have transactions as below
Transaction ID | Region | City | Factory | Product Category | Amount |
1 | West | Irvine | A | X | 100 |
2 | West | Irvine | B | X | 200 |
The second transaction wouldn't be mapped with the logic since the cross tab will only pick up the Factory 'A' due to the "FIRST" setting in the crosstab.
Thank you so much for your help!!!!
Solved! Go to Solution.
@PhilipMannering
I can it is brilliant from the result.
but still in the process of figuring what is the logic of your macro.
And there is no Control Parameter Tool either in the macro.
I have to say, looking around the community and get involved with questions is a really good learning process. 😁
@PhilipMannering Thank you for sharing the solution.
This works with the sample I gave you but it seems it is not working when I work with the full dataset because of the "FIRST" setting on the Crosstab tool. "FIRST" makes the logic miss other values created for '*'.
But still thank you so much for sharing your brilliant solution.
@Qiu You only need a Control Parameter if you're trying to 'inject' values into the macro.
@byung0917 It would only miss values if the Logic ID is not unique. And if it isn't then you would need to add a RecordID and use that to group data in the Crosstab Tool.
If you provide me an example of where it wouldn't work with the full data then I can amend the macro.
@PhilipMannering Hi!!! Thank you for the continuous support on this! I've added a new sample at the bottom of the original post. Thanks!!
@PhilipMannering Ah... I guess that was because I ran the data inside of the macro... It is very good that I got to learn this. Thank you so much!!!
Good stuff. Glad I could help. ʘ‿ʘ