简体   繁体   中英

Measures with different where clause - SQL

I have a scenario where I need to derive 2 measures from a base measure but both these measures have different where clause. Here are the details -

Table Structure

Year, Month, Revenue, YTD Revenue, Previous Month Revenue .

Revenue is a base measure provided and YTD Revenue and Previous Month Revenue are derived using Year, Month and Revenue.

Definitions

YTD Revenue - Sum of Revenue of all months for the current year until the said month. For example for Aug 2014 this value will be Revenue of Months from Jan to Aug and year = 2014.

Previous Month Revenue - Revenue of the last month. For Aug 2014, this will be Revenue of July 2014.

As is evident, we need different where clauses for YTD and Prev. Month Revenue. How can this be realized in SQL .

Please assist. Thanks.

Thanks for your responses. I am still to try this but this is what I think should work -

Determine the two measures in two different queries using self-join of the table. Join the output of both the queries using Year and Month.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM