Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Explanation of YTD

Hi,

Can any one explain the following code?

InYearToDate(TempDate, $(varMaxDate),0)*-1 as YTD

Why do they multiply with -1?

I would appreciate any help.

Thanks!

1 Solution

Accepted Solutions
danielrozental
Master II
Master II

Yes

-1 = True

0 = False

That's true in almost every computing language.

View solution in original post

4 Replies
danielrozental
Master II
Master II

InYearToDate returns true if date lies inside the part of year containing basedate up until and including the last millisecond of basedate.

True = -1.

So multiplying it by -1 would make -1 * -1 = 1.

They're probably counting how many dates are in that date and they want to sum 1's instead of summing -1's so that you get a possitive result.

Not applicable
Author

Thank you very much Daniel. 

This makes sense.  I thought true would give 1 and so I was wondering why do they multiply by -1.

Does it return 0 if false?

Thanks again

danielrozental
Master II
Master II

Yes

-1 = True

0 = False

That's true in almost every computing language.

Not applicable
Author

Thanks a lot Daniel.

Have a good one.