Forum

Add column based on...
 
Notifications
Clear all

Add column based on values from another table

6 Posts
2 Users
0 Reactions
91 Views
(@baxbax)
Posts: 125
Estimable Member
Topic starter
 

Hi,

I have a table that shows purchase order information. The table has a field called "PO Line Description". The description contains two pieces of data that I want to use to add columns based on a lookups of those values in two additional lookup tables.

An example of one of the descriptions is "Central & West - Controller of Site Safety - Midweek Day". From this I want to create a column called Region that picks out the "Central & West" part of the description. I also want another column called Shift that picks out the "Midweek Day" part.

I have two lookup tables that contain the values for the Regions and Shifts that I want to show in the columns. Can you create the new columns by looking up parts of the description string in another table? To add some further complexity the elements that I want to use in the description are not always in the same position in the string. For example there are some entries that show "Central & West - Controller of Site Safety - Call Off - Midweek Day". If you compare this to the first example you will see that it contains "Call Off" which the first didn't.

I have attached an example file. The source data is in the Extract sheet. The tables for the lookups are in the Lookups sheet. The Query sheet is where I want to show the results with the two columns added.

I tried merging the tables using Fuzzy lookup but I got zero matches.

Any ideas on how to do this would be gratefully received.

Thanks

Bax

 
Posted : 12/11/2021 1:58 pm
(@mynda)
Posts: 4762
Member Admin
 

Hi Bax,

You can use Add Column > Extract > Text before delimiter for the location and text after delimiter for the shift. The lookup tables are then redundant.

Mynda

 
Posted : 12/11/2021 7:51 pm
(@baxbax)
Posts: 125
Estimable Member
Topic starter
 

Hi Mynda,

That would work for the Region as in my example file the region is always at the start of the text string. However in the full live data set it is not always in that position. Also I wanted to pull out and match the Shift part if the description and the same applies to this. For example there are two entries in the data set as follows:

"Central & West - Controller of Site Safety - Midweek Day"

"Central & West - Controller of Site Safety - Call Off - Midweek Day"

I think you can use the extract option in conjunction with the advanced options to do it as they occur at the end of the text but in the live data this could appear anywhere say as follows:

"Central & West - Controller of Site Safety - Midweek Day - Call Off - 2021/22"

or

"Controller of Site Safety - Midweek Day - Central & West- Call Off - 2021/22"

You get the idea. It is random. Any idea how I would do this?

Thanks

 

Bax

 
Posted : 13/11/2021 7:59 am
(@baxbax)
Posts: 125
Estimable Member
Topic starter
 

Hi Mynda,

I think I have worked out how to do what I need. I have used Table.SelectRows and Text.Contains functions.

I added a custom column with the following formula to get the Region:

let CurrentText = [PO Line Description] in Table.SelectRows(Table_Region,each Text.Contains(CurrentText, [Region]))

This created a column with table values. I then expanded the column and it shows me the Region for those lines where there is a match in the text.

I did the same for the Shift field.

I have attached my file showing the solution.

Thanks

Bax

 
Posted : 13/11/2021 8:41 am
(@mynda)
Posts: 4762
Member Admin
 

Glad you figured out a solution.

Your example data did not illustrate that the region could sometimes be in the middle, nor did you explain that initially. You did mention that the position of the shift could be 2 or 3 delimiters in, which could be handled with 'text after delimiter'. For this reason, it's best if your sample file can illustrate all scenarios, that way we fully understand the issues to be handled.

Mynda

 
Posted : 13/11/2021 9:34 pm
(@baxbax)
Posts: 125
Estimable Member
Topic starter
 

Hi Mynda,

Consider my wrists well and truly slapped 🙂 I did try and make my initial enquiry as clear as I could. I thought that the second example of the shift that I needed would cover the issue where the bit I wanted could be anywhere in the text string.

Anyway I thought I would just add a bit of a warning to my solution having looked in to it a bit further. You need to be careful of duplicates. For example if you look in the solution file I uploaded and filter on PO Number 1332757 you will see that there are two lines for this in the Query sheet. One shows the Shift as Weekend, the other Weekend/B.Hol

1332757 Scotland - Roofer - Weekend/B.Hol Weekend
1332757 Scotland - Roofer - Weekend/B.Hol Weekend/B.Hol

The reason for this is because I have used the Text.Contains function to look for values in the Shift table in the Lookups sheet. That list contains "Weekend" so the lookup has picked up that this is in the PO Line Description field. The list also contains "Weekend/B.Hol" so it has then matched this and returned the second match.

I'm not sure if there is a clever way around this but useful to know that you might get duplicates which you will need to deal with.

Thanks

 

Bax

 
Posted : 16/11/2021 12:32 pm
Share: