Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

MTD

I handle fiscal dates by creating a table of dates and assigning the day dates to a month. My questions are what if a sales rep wants to see his numbers compared to last year Month to Date. So only through the 25th of July of this year and last.


This year's data would be ok because there is no data for any dates later than the 25th. But last year has a full month's data. What's the best way to limit the data of July of last year to be July 1st through the 25th?

4 Replies
Not applicable
Author

Hi James, This is a very generic question, can you please elobrate more?

Regards,

Amit

Not applicable
Author

Im not sure if I fully understand your question but one way to solve this would be to create dateflags in the script.

Datefield be the name of your date field.

Then refer to the flags in your expression. E.g. sum(if(FLAG_MTD_LastYear='1',Sales)


If( InMonthToDate (Datefield,Today(),0),1) as FLAG_MTD_ThisYear,


If( InMonthToDate (Datefield,Today(),-12),1) as FLAG_MTD_LastYear,







Not applicable
Author

Creating these binary flags, as FHoeglund has mentioned is an excellent way of doing exactly what you're looking for. The only thing I would add/change from what was already said is how to refer to it within your expressions.


FHoeglund wrote:Then refer to the flags in your expression. E.g. sum(if(FLAG_MTD_LastYear='1',Sales)


Since your flags are binary you can multiply them by the field you want to sum and the only rows that get summed are the ones for which the binary flag equals '1'. (ie. Sum(FLAG_MTD_LastYear * Sales) ). This method is quite a bit faster than IF() statements because of the difference in operations required by the CPU.

John Witherspoon has also recently posted experimental results on performance differences between using IF, multiplication and set analysis using binary flags (Set analysis example: Sum( {$<FLAG_MTD_LastYear={1}>} Sales) ). His post is here:

http://community.qlik.com/forums/p/17188/71371.aspx

His findings seem to indicate Set analysis is faster than the other two methods. I have not been able to verify this, but I can say that switching from If statements to multiplication of binary flags gave us HUGE performance benefits.

Hopefully this helps,

sjprows

Not applicable
Author

Great! Thanks for the posts.. i wasn't thinking of putting them into flag form which where i was having problems.