Home

How can I search a range of text and return value of text from first column?

%3CLINGO-SUB%20id%3D%22lingo-sub-909453%22%20slang%3D%22en-US%22%3EHow%20can%20I%20search%20a%20range%20of%20text%20and%20return%20value%20of%20text%20from%20first%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-909453%22%20slang%3D%22en-US%22%3E%3CP%3EI%20want%20to%20search%20a%20range%20of%20text%20(exams%20students%20have%20signed%20up%20for)%20and%20create%20a%20list%20of%20students%20who%20have%20signed%20up%20for%20each%20exam.%26nbsp%3B%20I%20would%20like%20it%20to%20look%20similar%20to%20the%20table%20below.%26nbsp%3B%20Can%20anyone%20recommend%20a%20formula%20that%20would%20complete%20this%20task%3F%3C%2FP%3E%3CTABLE%20border%3D%221%22%3E%3CTBODY%3E%3CTR%3E%3CTD%3E%3CSTRONG%3EName%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EExam%201%26nbsp%3B%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EExam%202%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EExam%203%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EExam%204%3C%2FSTRONG%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EDemitri%26nbsp%3B%3C%2FTD%3E%3CTD%3ESpanish%3C%2FTD%3E%3CTD%3EMath%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ELouis%3C%2FTD%3E%3CTD%3EEnglish%3C%2FTD%3E%3CTD%3EMusic%3C%2FTD%3E%3CTD%3EMath%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EAngela%3C%2FTD%3E%3CTD%3EMath%3C%2FTD%3E%3CTD%3ESpanish%3C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R%3E%3CTR%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EEmily%3C%2FTD%3E%3CTD%3EAngela%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EDequan%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EEmily%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-909453%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-909489%22%20slang%3D%22en-US%22%3ERe%3A%20How%20can%20I%20search%20a%20range%20of%20text%20and%20return%20value%20of%20text%20from%20first%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-909489%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F424654%22%20target%3D%22_blank%22%3E%40mpcassid%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20can%20be%20done%20with%20Power%20Query.%3C%2FP%3E%3CP%3ESee%20attached%20file.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-909496%22%20slang%3D%22es-ES%22%3ERe%3A%20How%20can%20I%20search%20a%20range%20of%20text%20and%20return%20value%20of%20text%20from%20first%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-909496%22%20slang%3D%22es-ES%22%3E%3CP%3EGood%20morning%2C%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F424654%22%20target%3D%22_blank%22%3E%40mpcassid%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F137229i6F1944CA1C8397F0%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Solucion.png%22%20title%3D%22Solucion.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-909657%22%20slang%3D%22en-US%22%3ERe%3A%20How%20can%20I%20search%20a%20range%20of%20text%20and%20return%20value%20of%20text%20from%20first%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-909657%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1639%22%20target%3D%22_blank%22%3E%40Detlef%20Lewin%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20adding%20a%20bit%20of%20code%20your%20solution%20could%20be%20shortened%20and%20be%20independent%20on%20number%20of%20names%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Elet%0A%20%20%20%20Source%20%3D%20Tabelle1%2C%0A%20%20%20%20UnpivotOtherColumns%20%3D%20Table.UnpivotOtherColumns(Source%2C%20%7B%22Name%22%7D%2C%20%22Attribute%22%2C%20%22Value%22)%2C%0A%20%20%20%20GroupRows%20%3D%20Table.Group(UnpivotOtherColumns%2C%20%7B%22Value%22%7D%2C%20%7B%7B%22Names%22%2C%20each%20%5BName%5D%7D%7D)%2C%0A%20%20%20%20Result%20%3D%20Table.FromRows(List.Zip(GroupRows%5BNames%5D)%2CGroupRows%5BValue%5D)%0Ain%0A%20%20%20%20Result%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
mpcassid
New Contributor

I want to search a range of text (exams students have signed up for) and create a list of students who have signed up for each exam.  I would like it to look similar to the table below.  Can anyone recommend a formula that would complete this task?

NameExam 1 Exam 2Exam 3Exam 4
Demitri SpanishMath  
LouisEnglishMusicMath 
AngelaMathSpanish  
DequanMusicPsychologyEnglishMath
EmilyPsychologyEnglishMath Music
     
SpanishMusicMath EnglishPsychology
DemitriLouisDemitriLouisDequan
AngelaDequanLouisDequanEmily
 EmilyAngela  
  Dequan   
  Emily  
9 Replies

@Detlef Lewin 

With adding a bit of code your solution could be shortened and be independent on number of names

let
    Source = Tabelle1,
    UnpivotOtherColumns = Table.UnpivotOtherColumns(Source, {"Name"}, "Attribute", "Value"),
    GroupRows = Table.Group(UnpivotOtherColumns, {"Value"}, {{"Names", each [Name]}}),
    Result = Table.FromRows(List.Zip(GroupRows[Names]),GroupRows[Value])
in
    Result

 

Thanks for the quick reply.  Can you tell me how I could apply your query to my current workbook?@Detlef Lewin 

@mpcassid 

I repeated solution which @Detlef Lewin suggested, only modified the code a bit.

Perhaps you are not familiar with Power Query, when from scratch.

If you are on Excel for Mac that solution doesn't work. If on Excel 2016 or later, Power Query is built into Excel. If earlier version (2010, 2013) you need to download from Microsoft Downloads and install free Power Query add-in.

 

With your actual file - you have at least two options. First, which is preferable convert your source data into Excel Table. Stay within the range (or select it), Ctrl+T, check your table has headers, Enter. Rename the table as suitable, in my sample tblSignUp.

 

Second option use your data as named range, Select it, better with some gap on future expansion, with one-two empty columns to the right and with empty rows down. In Formulas->Name Manager give the name to the range, let say rngSignUp.

 

Create new blank query like Data->Get Data->From Other Sources->Blank Query. Power Query editor will be opened, here find Home->Advanced Editor. Copy your variant of code from here below, or from attached file. Ctrl+A and paste this code into Advanced Editor window -> Done. Be sure query works, after that Home->Close and Load To into Excel sheet.

 

Above is one variant of steps to perform, that could other ways, just keep an idea.

Code to the table:

let
    Source = Excel.CurrentWorkbook(){[Name="tblSignUp"]}[Content],
    UnpivotOtherColumns = Table.UnpivotOtherColumns(
        Source,
        {"Name"}, "Attribute", "Value"
    ),
    GroupRows = Table.Group(
        UnpivotOtherColumns,
        {"Value"}, {{"Names", each [Name]}}
    ),
    Result = Table.FromRows(
        List.Zip(GroupRows[Names]),GroupRows[Value]
    )
in
    Result

Code for the range:

let
    Source = Excel.CurrentWorkbook(),
    FilteredOnRange = Table.SelectRows(Source, each ([Name] = "rngSignUp")),
    KeepTable = Table.SelectColumns(FilteredOnRange,{"Content"}),
    ColumnNames = Table.ColumnNames(KeepTable[Content]{0}),
    ExpandRange = Table.ExpandTableColumn(
        KeepTable,
        "Content",
        ColumnNames,
        ColumnNames
    ),
    ExamsToHeaders = Table.PromoteHeaders(
        ExpandRange,
        [PromoteAllScalars=true]
    ),
    NewColumnNames = Table.ColumnNames(ExamsToHeaders),
    ColumnsToKeep = List.RemoveMatchingItems(
        NewColumnNames,ColumnNames),
    KeepExamsColumns = Table.SelectColumns(
        ExamsToHeaders,
        ColumnsToKeep
    ),
    RemoveEmptyRows = Table.SelectRows(
        KeepExamsColumns,
        each ([Name] <> null)
    ),
    UnpivotOtherColumns = Table.UnpivotOtherColumns(
        RemoveEmptyRows,
        {"Name"}, "Attribute", "Value"
    ),
    GroupRows = Table.Group(
        UnpivotOtherColumns,
        {"Value"}, {{"Names", each [Name]}}
    ),
    Result = Table.FromRows(
        List.Zip(GroupRows[Names]),GroupRows[Value]
    )
in
    Result

Alternatively you may not care about the code, just take @Detlef Lewin variant and repeat all steps from his query on your actual data using Power Query user interface only. Here you shall be careful with number and names of the columns.

Thank you so much.  You have been extremely helpful.@Sergei Baklan 

@mpcassid 

The following is a solution using a modern dynamic array formula

= FILTER( Name, MMULT(N(Exams=@Subject), {1;1;1;1} ) )

 

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
21 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies