Forum Discussion

othafa's avatar
othafa
Copper Contributor
Apr 24, 2019
Solved

Vlookup to find multiple variations of a text string

Hi, first time post here so bear with me!

 

I am trying to create a worksheet that displays a list of shift types with names of staff allocated that shift over the period of a week.

I can do this for straightforward shifts but occasionally we have to ask staff to double up on shifts and the vlookup formula I am using wont find the double shifts.

The problem is that there are too many possible combinations of double shifts for me to list them all on the worksheet so I need a formula that can find any possible combination and display the staff member who has been allocated it?

Sample File attached.

 

Thanks

28 Replies

  • othafa 

    A formula solution.  The key element is to perform a wildcard search for anything that contains a shift name, e.g. search for "*LMP*".  There is a catch that the abbreviations for Early and Late are to be found within other shift codes so I converted them to "E0" and "L0" to avoid 'false positives'.

     

    = IFERROR( INDEX( Name, MATCH( shift, INDEX(shiftTable, 0, day), 0 ) ), "" )

    The names 'day' and 'shift' are relative references and the innermost INDEX returns the 3 rows for a given day of the table.

     

    As for your other line of exploration, Power Query is available as an Office 2010 add-in free of charge from Microsoft.  Your IT department could install it for you and I would recommend that they evaluate it themselves!

     

    • othafa's avatar
      othafa
      Copper Contributor
      Hi, I've now converted the original file to use the formula you gave me but it's not working properly. I'm on a steep learning curve here as I've never worked with arrays before and hardly ever with Index and Match.

      Anyway I set up the named ranges for the constants adjusted for the real data and set it going. It correctly gives me the names for the shifts on Monday but just repeats that name for the rest of the week.

      I've run the Evaluate Formula feature and as it steps through it everything seems to be going right until the last step when it reverts to the name it gave for Monday.

      Any thoughts?
      • PeterBartholomew1's avatar
        PeterBartholomew1
        Silver Contributor

        othafa 

        The catch might be that 'day' is a relative reference to the indices 1,...7 above the table.  To get a fresh value for each column, the array formula is applied to a single column and then copied across to give a set of 7 array formulas rather than one single array formula.

    • Detlef_Lewin's avatar
      Detlef_Lewin
      Silver Contributor

      PeterBartholomew1 

      Did you compare your solution with my solution?

      Your missing some shifts: DO, LMP1.

      And your missing multiple names for the same shift on the same day.

      And LMP produces false positives because of LMP1 and LMP2.

       

      • othafa's avatar
        othafa
        Copper Contributor

        Detlef_Lewin PeterBartholomew1 

        Peter's solution looks good, I'll need to run it in the real schedule obviously to test it.

         

        Not concerned if it doesnt pick up DO as those are days off which we don't need to display on sheet 2 (in Peter's solution I was intending to deselect DO and AL in the filter section of the pivot table using a macro) but would be concerned if it doesnt pick up duplicates at all.

         

        My bad, the LMP should be LMP1 but we only use a number in shift codes if there are two people doing the same shift. In other words there is a CWE but will never be a CWE1 or CWE2. I think Ive just resolved the duplicate issue....the only duplicates we do use are the E and L shifts and we could possibly number them so no need to call them EO and LO.

         

        Ill try the download myself but company admin privaledges may prevent me doing that, if so and I get someone in IT to look at it for me they may just come back and tell me it wont work!

         

        Watch this space and thanks again for the help.

      • PeterBartholomew1's avatar
        PeterBartholomew1
        Silver Contributor

        SergeiBaklan 

        For me, what the documentation suggests and what actually happened were not the same thing.  Power Query and Power Pivot both installed despite my not having the correct version of Office.

         

        Now I am using Office 365 insider but that is because I was desperate to evaluate modern Dynamic Arrays (they are superb and now provide the basis of everything I do outside Power Query).

    • PeterBartholomew1's avatar
      PeterBartholomew1
      Silver Contributor

      Detlef_Lewin 

      I liked the reference to the Bill Jelen podcast.  I have yet to get around to using measures and DAX so perhaps this will encourage me to seek out new problems where I can use it!

    • othafa's avatar
      othafa
      Copper Contributor

      Detlef_Lewin 

      Thanks for this, it certainly does what I want. 

       

      Is there a way to convert sheet 1 into the table (A1:C24) you created in Tabelle1. I ask because the format of sheet1 is fixed as it is?

       

      Thanks.

      • Detlef_Lewin's avatar
        Detlef_Lewin
        Silver Contributor

        othafa 

        That is the PQ part. Goto to the PQ editor to see the queries and steps.

        To load the table into PQ I assigned a name to the table range (-> name manager),

         

Resources