I have data in a table. I am trying to use the query, or similar, function in sheets to then show a comparison month over month as well as trailing 3 month reveue.
CodePudding user response:
try:
=ARRAYFORMULA(QUERY({Data!A:C, IFERROR(
{"Prior month Revenue", "MoM Change", "% MoM", "Trailing 3 month revenue";
IFNA(VLOOKUP(Data!A2:A&EOMONTH(Data!B2:B, -1),
QUERY({Data!A2:A&Data!B2:B, Data!C2:C}, "select Col1,sum(Col2) group by Col1"), 2, ), 0), Data!C2:C-IFNA(VLOOKUP(Data!A2:A&EOMONTH(Data!B2:B, -1),
QUERY({Data!A2:A&Data!B2:B, Data!C2:C}, "select Col1,sum(Col2) group by Col1"), 2, ), 0), (Data!C2:C-IFNA(VLOOKUP(Data!A2:A&EOMONTH(Data!B2:B, -1),
QUERY({Data!A2:A&Data!B2:B, Data!C2:C}, "select Col1,sum(Col2) group by Col1"), 2, ), 0))/ (IFNA(VLOOKUP(Data!A2:A&EOMONTH(Data!B2:B, -1),
QUERY({Data!A2:A&Data!B2:B, Data!C2:C}, "select Col1,sum(Col2) group by Col1"), 2, ), 0)), Data!C2:C IFNA(VLOOKUP(Data!A2:A&EOMONTH(Data!B2:B, -1),
QUERY({Data!A2:A&Data!B2:B, Data!C2:C}, "select Col1,sum(Col2) group by Col1"), 2, ), 0) IFNA(VLOOKUP(Data!A2:A&EOMONTH(Data!B2:B, -2),
QUERY({Data!A2:A&Data!B2:B, Data!C2:C}, "select Col1,sum(Col2) group by Col1"), 2, ), 0)}, 0)}, "where Col1 is not null", 1))