使用 Google Sheets 的 QUERY 函数按年拆分收入
Split revenue by year with Google Sheets' QUERY function
我从财务部门获得了每月的收入数据,我可以将这些数据干净地输入到报告格式中。它的月度数据在单个列中列出了所有收入。我需要按年份(2018 年、2019 年等)拆分收入。
我认为我需要为此使用查询函数,但如果您有其他解决方案,那么我也愿意接受。
数据如下所示:
Client Source Month Year Revenue
abc Google 1 2019 100
abc Google 1 2018 100
abc Facebook 1 2018 50
abc Facebook 2 2018 50
我需要它看起来像这样:
Client Source Month 2018 Revenue 2019 Revenue
abc Google 1 100 100
abc Facebook 1 50 0
abc Facebook 2 50 0
我熟悉查询函数,但不知道如何执行此操作。
伪代码类似于:
select Client,
Source,
Month,
Case when Year in 2019 then sum(Revenue) as 2019 Revenue else 0 end,
Case when Year in 2018 then sum(Revenue) as 2018 Revenue else 0 end
from Data
Group by Client, Source, Month
如果我需要提供任何其他信息,请告诉我。感谢您对这个问题的帮助。
=QUERY(A1:E, "select A,B,C,sum(E) where A is not null group by A,B,C pivot D", 1)
我从财务部门获得了每月的收入数据,我可以将这些数据干净地输入到报告格式中。它的月度数据在单个列中列出了所有收入。我需要按年份(2018 年、2019 年等)拆分收入。
我认为我需要为此使用查询函数,但如果您有其他解决方案,那么我也愿意接受。
数据如下所示:
Client Source Month Year Revenue
abc Google 1 2019 100
abc Google 1 2018 100
abc Facebook 1 2018 50
abc Facebook 2 2018 50
我需要它看起来像这样:
Client Source Month 2018 Revenue 2019 Revenue
abc Google 1 100 100
abc Facebook 1 50 0
abc Facebook 2 50 0
我熟悉查询函数,但不知道如何执行此操作。
伪代码类似于:
select Client,
Source,
Month,
Case when Year in 2019 then sum(Revenue) as 2019 Revenue else 0 end,
Case when Year in 2018 then sum(Revenue) as 2018 Revenue else 0 end
from Data
Group by Client, Source, Month
如果我需要提供任何其他信息,请告诉我。感谢您对这个问题的帮助。
=QUERY(A1:E, "select A,B,C,sum(E) where A is not null group by A,B,C pivot D", 1)