
Month by Month Comparison
Neil Miller May 11, 2009 9:51 PM (in response to sunil yadav)You can accomplish this through Set Analysis and a dollar sign expansion.
Your expressions should look something like this:
Sum( {<Month = {$(#=Month(Now()))}>} Fact_Field)
The portion in parenthesis after the dollar sign is the dollar sign expansion and will be evaluated before the Set Analysis is considered. You would do something similar for the previous month.

Month by Month Comparison
Neil Miller May 11, 2009 10:19 PM (in response to Neil Miller)The expression I wrote above is Set Analysis. For an overview of Set Analysis, see page 327 of Book III of the Reference Manual. For forum entries related to Set Analysis, click the Set Analysis link under Popular Tags on the right of the forum topics.
There are quite a few variations of Set Analysis that would accomplish what you're looking for. Oleg's method of using flags is just as simple and effective. Since only you know how your data looks, we can't write the expressions for you.


Month by Month Comparison
Oleg Troyansky May 11, 2009 9:54 PM (in response to sunil yadav)If you are using 8.5, you can use Set Analysis to limit data to Current Month and to Prior Month.
Alternatively, you can preload Flags in your data  for the Current Month, set CurrMonth_Flag = 1 (keep it as null() for all other months) and for the Previous Month, set PriorMonth_Flag = 1. Then, your chart expressions are very simple:
Curr Month Sales = sum(Sales*CurrMonth_Flag)
Prior Month Sales = sum(Sales*PriorMonth_Flag)
cheers,
Oleg

Month by Month Comparison
sunil yadav May 11, 2009 10:10 PM (in response to Oleg Troyansky )Hi,
I amnew to QlikView so not aware on Set Analysis. Can you please provide how I can calculate for current Month and Last month using set analysis.

Month by Month Comparison
John Witherspoon May 11, 2009 10:20 PM (in response to Oleg Troyansky )Even with flags, I'd probably use set analysis. I believe that sum(Sales*CurrMonth_Flag) will force QlikView to examine every row. With set analysis, sum({<CurrMonth_Flag={1}>}Sales), I'm pretty certain that QlikView will only examine the rows with the flag set.
While I don't guarantee that my explanation is the right one, testing appears to show the expected performance differences. I created a 10 million row table with three customers assigned at random, a flag assigned at random, and a sales amount assigned at random. I made three different charts for the sum of flagged sales by customer, with different expressions to return the same result. Here is the calculation time for each:
531 sum({<Flag={1}>Sales)
750 sum(Flag*Sales)
781 sum(if(Flag=1,Sales))(edit: That was with the flag set on 50% of the records. With the flag set on only 5% of the records, I see this:
141 sum({<Flag={1}>Sales)
687 sum(Flag * Sales)
641 sum(if(Flag=1,Sales))And with only 0.5% of the records flagged:
78 sum({<Flag={1}>Sales)
656 sum(Flag * Sales)
594 sum(if(Flag=1,Sales))Basically, the larger the table, and the smaller the percentage of rows you're trying to identify, the more it will help to use set analysis over an if or a multiply. I personally just make it a habit to use it all the time.)

Month by Month Comparison
Neil Miller May 11, 2009 10:50 PM (in response to John Witherspoon )Thanks for the explanation John. I like to use Set Analysis because it is so easy to implement. I almost take the calculation effeciency for granted. I've never seen it quantified as actual times before. I am suprised that an if seems to be less costly than (or at least equally costly to) a multiplication though.
The dataset I am currently working with was designed prior to Set Analysis being introduced, so it utilizes flags. Using flags along with Set Analysis seems to offer the best of both worlds, giving you speed and an easy to follow syntax.

