Adding Filter Columns In Query When Calculation Year Over Year Growth in Apache Superset SQL LAB

Viewed 244

I have been trying to calculate year over year growth for Cost. Without Lag() I need to do it in MYSQL (SQL LAB in Apache Superset), then I'm going to create a widget using that query.

I could do the calculation and the answers are correct. But I could group the calculated YOY metric only based on YEAR column.

But I need other 3 dimension columns for FILTER. If I use those dimensions in query and If I add those columns in GROUP_BY statement, My output is wrong. This is the output I got from the query which I have created:

This is the output I got from the query which I have created

If you notice the This year and Last year company column, its not correct when compared with Years. So, If I use that column in query, Its not giving correct output. Its not correctly grouping by the Company.

Any suggestions to calculate Year Over Year Growth metric with other dimension columns I need for Filters ?

NOTE: Without LAG() I have used SQL Query - Year by Year Growth of Sales as the ref. I did use the same method to calculate YOY.

0 Answers
Related