0
votes

I have a table with the following data:

Column A: Country Page

Column B: Link to post

Column C: Date posted

I created the following query to get the last date each Country Page posted:

=QUERY('Post Level'!A:C, "select A, max(C) where A<>'#N/A' and A<>'' group by A label max(C) 'Last Posted Date'",1)

The query works perfectly. I'd like to add also a link to the last post. So I changed it to:

=QUERY('Post Level'!A:C, "select A,B max(C) where A<>'#N/A' and A<>'' group by A,B label max(C) 'Last Posted Date'",1)

This version doesn't work. I get duplicate entries for each country.

Ideally I would like to see: Country Page, Last Date Country Posted, Link to last post

1
IMHO a really tough question. If I were faced with doing this in SQL I would find the last posted dates for each country like you did, then realise that the only way to get the corresponding links would be to link back to the original data using an inner join on Country page = country from my query and date = last date from my query. Unfortunately GS doesn't have an inner join although you can simulate it stackoverflow.com/questions/14796620/… ...tricky.Tom Sharpe
BTW would it be possible to show us a few lines of data plz? No promises that it will yield an answer, but would aid thought processes.Tom Sharpe

1 Answers

1
votes

Well here is a proof of concept that it is do-able:

=ArrayFormula(iferror(vlookup({unique(A:A)&query(A:C, "select max(C) group by A offset 1 label max(C) 'Date'")},{A:A&C:C,B:B},2,false),""))

So I am concatenating the Country and Last Date and using them as a lookup value to get the associated Link.

The reason for using Unique rather than a query to get the list of countries is that you can't just put

select A group by A

You have to have at least one aggregate. As long as unique returns the countries in the same order as the group by (which it should do), this will work correctly.

enter image description here