Google Sheets – How to Filter Cell Data Using QUERY and IMPORTDATA

filterformulasgoogle sheetsgoogle-sheets-queryimportdata

I am attempting to grab data from a cell, by using additional data in the cell above it to make sure its correct.
Here is the data, each line is put into a cell by the formula.

<total_count>6</total_count>
<games>
<message>
<appid>376210</appid>
<name>The Isle</name>
<playtime_2weeks>4300</playtime_2weeks>
<playtime_forever>23973</playtime_forever>
</message>
<message>
<appid>4000</appid>
<name>Garry&apos;s Mod</name> --------using this
<playtime_2weeks>289</playtime_2weeks> ------to get this!
<playtime_forever>277810</playtime_forever>
</message>
<message>
<appid>578080</appid>
<name>PLAYERUNKNOWN&apos;S BATTLEGROUNDS</name>
<playtime_2weeks>59</playtime_2weeks>
<playtime_forever>8585</playtime_forever>
<img_icon_url>93d896e7d7a42ae35c1d77239430e1d90bc82cae</img_icon_url>
<img_logo_url>2d2732a33511b58c69aff6b098a22687a3bb8533</img_logo_url>
</message>
<message>

The formula I am currently using is

=QUERY(IMPORTDATA(A1)," select Col1,Col2 where Col2 = '2weeks' and Col2 matches 'Garry'")

It outputs <name>Garry&apos;s Mod</name> and I can't select only '2weeks' since that is repeated several times, and for different games.

Additionally, the layout may change at anytime. The Isle is current at the top, but it may change to be at the middle, or bottom of the list at any time. I know if I spent more time on this, I could just use separate formulas to achieve my goal, however I'm attempting to learn how to used combined formulas. Less clutter, more options, and easier to look at.

Any ideas?

Best Answer

=REGEXEXTRACT(QUERY({{A1:A25; ""}, {""; A1:A25}}, 
 "select Col1 where Col2 contains 'Garry'", 0), 
 ">(.*)<")

0