SOLVED

Extract a string from a "properties" field

%3CLINGO-SUB%20id%3D%22lingo-sub-1348412%22%20slang%3D%22en-US%22%3EExtract%20a%20string%20from%20a%20%22properties%22%20field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1348412%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20Excel%20experts%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20struggling%20with%20an%20'extract'%20type%20of%20problem.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBasically%20I%20need%20to%20extract%20a%20string%20of%20unknown%20length%20from%20a%20properties%20field.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20string%20may%20or%20may%20not%20be%20present%20in%20the%20field.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20way%20I%20know%20the%20string%20is%20present%20is%20if%20it%20is%20preceded%20by%20a%20property%20string.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20property%20may%20or%20may%20not%20be%20present%20in%20the%20field.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20I%20need%20to%20extract%20Female%20if%20gender%20exists%2C%20or%20driving_license%20if%20document%20type%20exisits.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20I'm%20trying%20to%20do%20is%20to%20create%20a%20set%20of%20a%20gender%20columns%20that%20has%20the%20values%20from%20this%20compound%20field%3A%20a%20gender%20column%2C%20a%20nationality%20column%2C%20a%20document_type%20column%2C%20a%20date_of_expiry%2C%20issuing_country%20columns%20that%20may%20or%20may%20not%20have%20the%20extracted%20values.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGender%20is%20fairly%20easy%20because%20it's%20the%20first%2C%20i%20can%20use%20nested%20if's%20and%20left's%20to%20get%20male%20or%20female%2C%20its%20the%20rest%20of%20the%20fields%20that%20are%20complex%20to%20extract.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIssuing%20date%2C%20issuing%20country%2C%20and%20date%20of%20expiry%20values%20are%20standard%20lengths%20so%20these%20would%20be%20easier%20but%20the%20document_type%20values%20can%20vary%20in%20length.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBelow%20is%20some%20sample%20data%20records%20of%20the%20property%20field%3A%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%7B'gender'%3A%20'Female'%2C%20'nationality'%3A%20'PRT'%2C%20'document_type'%3A%20'national_identity_card'%2C%20'date_of_expiry'%3A%20'2019-11-13'%2C%20'issuing_country'%3A%20'PRT'%7D%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%7B'gender'%3A%20'Male'%2C%20'nationality'%3A%20'LTU'%2C%20'document_type'%3A%20'passport'%2C%20'date_of_expiry'%3A%20'2026-01-12'%2C%20'issuing_country'%3A%20'LTU'%7D%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%7B'gender'%3A%20'Female'%2C%20'nationality'%3A%20'CZE'%2C%20'document_type'%3A%20'national_identity_card'%2C%20'date_of_expiry'%3A%20'2023-08-26'%2C%20'issuing_country'%3A%20'CZE'%7D%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%7B'gender'%3A%20'Female'%2C%20'issuing_date'%3A%20'2012-05'%2C%20'document_type'%3A%20'national_identity_card'%2C%20'issuing_country'%3A%20'FRA'%7D%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%7B'gender'%3A%20'Male'%2C%20'document_type'%3A%20'driving_licence'%2C%20'date_of_expiry'%3A%20'2019-07-09'%2C%20'issuing_country'%3A%20'GBR'%7D%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%7B'gender'%3A%20'Male'%2C%20'issuing_date'%3A%20'2010-12'%2C%20'document_type'%3A%20'national_identity_card'%2C%20'issuing_country'%3A%20'FRA'%7D%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%7B'gender'%3A%20'Male'%2C%20'document_type'%3A%20'driving_licence'%2C%20'date_of_expiry'%3A%20'2026-04-25'%2C%20'issuing_country'%3A%20'GBR'%7D%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%7B'gender'%3A%20'Male'%2C%20'nationality'%3A%20'GBR'%2C%20'document_type'%3A%20'passport'%2C%20'date_of_expiry'%3A%20'2025-01-25'%2C%20'issuing_country'%3A%20'GBR'%7D%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%7B'gender'%3A%20'Male'%2C%20'nationality'%3A%20'ESP'%2C%20'document_type'%3A%20'national_identity_card'%2C%20'date_of_expiry'%3A%20'2022-04-18'%2C%20'issuing_country'%3A%20'ESP'%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-d%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1348412%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20on%20Mac%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1348474%22%20slang%3D%22en-US%22%3ERe%3A%20Extract%20a%20string%20from%20a%20%22properties%22%20field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1348474%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F642188%22%20target%3D%22_blank%22%3E%40davidwabel%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20quick%20solution%20with%20PQ.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1348696%22%20slang%3D%22en-US%22%3ERe%3A%20Extract%20a%20string%20from%20a%20%22properties%22%20field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1348696%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%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20you%20describe%20how%20you%20did%20this%20%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIdeally%20I%20need%20the%20output%20into%20discreet%20columns%20next%20to%20each%20source%20field%2C%20gender%2C%20nationality%2C%20etc.%20as%20opposed%20to%20repeating%20rows.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-d%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1348706%22%20slang%3D%22en-US%22%3ERe%3A%20Extract%20a%20string%20from%20a%20%22properties%22%20field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1348706%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%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20think%20you%20mean%20Power%20Query%3F%20Is%20this%20available%20on%20Mac%20Excel%202016%20%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-d%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1348868%22%20slang%3D%22en-US%22%3ERe%3A%20Extract%20a%20string%20from%20a%20%22properties%22%20field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1348868%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F642188%22%20target%3D%22_blank%22%3E%40davidwabel%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENo%2C%20PQ%20for%20Excel%20on%20Mac%20is%20still%20in%20development.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1351035%22%20slang%3D%22en-US%22%3ERe%3A%20Extract%20a%20string%20from%20a%20%22properties%22%20field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1351035%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%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20other%20method%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-d%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1351549%22%20slang%3D%22en-US%22%3ERe%3A%20Extract%20a%20string%20from%20a%20%22properties%22%20field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1351549%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F642188%22%20target%3D%22_blank%22%3E%40davidwabel%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20next%20best%20thing%20would%20be%20VBA.%20But%20that%20is%20not%20my%20expertise.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Hello Excel experts

 

I'm struggling with an 'extract' type of problem.

 

Basically I need to extract a string of unknown length from a properties field. 

 

The string may or may not be present in the field. 

 

The way I know the string is present is if it is preceded by a property string. 

 

The property may or may not be present in the field. 

 

For example, I need to extract Female if gender exists, or driving_license if document type exisits.

 

What I'm trying to do is to create a set of a gender columns that has the values from this compound field: a gender column, a nationality column, a document_type column, a date_of_expiry, issuing_country columns that may or may not have the extracted values. 

 

Issuing date, issuing country, and date of expiry values are standard lengths so these would be easier but the document_type values can vary in length. 

 

Below is some sample data records of the property field:  

 

{'gender': 'Female', 'nationality': 'PRT', 'document_type': 'national_identity_card', 'date_of_expiry': '2019-11-13', 'issuing_country': 'PRT'}

 

{'document_type': 'national_identity_card', 'date_of_expiry': '2020-08-24', 'issuing_country': 'PRT'}


{'gender': 'Male', 'nationality': 'LTU', 'document_type': 'passport', 'date_of_expiry': '2026-01-12', 'issuing_country': 'LTU'}


{'gender': 'Female', 'nationality': 'CZE', 'document_type': 'national_identity_card', 'date_of_expiry': '2023-08-26', 'issuing_country': 'CZE'}


{'gender': 'Female', 'issuing_date': '2012-05', 'document_type': 'national_identity_card', 'issuing_country': 'FRA'}


{'gender': 'Male', 'document_type': 'driving_licence', 'date_of_expiry': '2019-07-09', 'issuing_country': 'GBR'}


{'gender': 'Male', 'issuing_date': '2010-12', 'document_type': 'national_identity_card', 'issuing_country': 'FRA'}


{'gender': 'Male', 'document_type': 'driving_licence', 'date_of_expiry': '2026-04-25', 'issuing_country': 'GBR'}


{'gender': 'Male', 'nationality': 'GBR', 'document_type': 'passport', 'date_of_expiry': '2025-01-25', 'issuing_country': 'GBR'}


{'gender': 'Male', 'nationality': 'ESP', 'document_type': 'national_identity_card', 'date_of_expiry': '2022-04-18', 'issuing_country': 'ESP'}

 

Thanks! 

 

-d 

6 Replies
Highlighted
Best Response confirmed by davidwabel (New Contributor)
Solution

@davidwabel 

A quick solution with PQ.

 

Highlighted

@Detlef Lewin 

 

Thanks!

 

Can you describe how you did this ? 

 

Ideally I need the output into discreet columns next to each source field, gender, nationality, etc. as opposed to repeating rows.

 

-d 

Highlighted

@Detlef Lewin 

 

I think you mean Power Query? Is this available on Mac Excel 2016 ? 

 

-d 

Highlighted

@davidwabel 

No, PQ for Excel on Mac is still in development.

 

Highlighted

@Detlef Lewin 

 

Thanks

 

Any other method ?

 

-d

Highlighted

@davidwabel 

The next best thing would be VBA. But that is not my expertise.