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

YTD and Previous YTD

Hi,

I'm trying to figure out a simple YTD and previous YTD expression:

1.  The year follows the calendar year, so I'm looking for 1/1/17 through 6/13/17 in comparison to 1/1/16 through 6/13/16.

2.  The date I'm using is the Transactions.Txn Date

3.  I'm trying to find sales using the Transactions.Amount With Sign field

I've looked at other boards, but it's a little over my head.  Can anyone help?


Thanks-

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

For this  year :

1/1/17 through 6/13/17 in

=Sum({$ <Transactions.Txn Date={"$(='>=' & Date(YearStart(Max(Transactions.Txn Date)), 'MM/DD/YYYY') & '<=' & Date((Max(Transactions.Txn Date)), 'MM/DD/YYYY'))"}>} [Transactions.Amount])

for previous year

/1/16 through 6/13/16.

=Sum({$ <Transactions.Txn Date={"$(='>=' & Date(YearStart(Max(Transactions.Txn Date),-1), 'MM/DD/YYYY') & '<=' & Date(addyears(Max(Transactions.Txn Date),-1), 'MM/DD/YYYY'))"}>} [Transactions.Amount])

View solution in original post

3 Replies
oscar_ortiz
Partner - Specialist
Partner - Specialist

Nicole,

The most common way of dealing with that is by building a Master Calendar based on your data, in your case the Transactions.Txn Date field.  Part of that master calendar will be to determine what dates are considered YTD or PYTD.

Check out these posts for help:

The Master Calendar

Year-over-Year Comparisons

You can then use the fields from the master calendar in your expression.

Good Luck!

Oscar

Anonymous
Not applicable
Author

For this  year :

1/1/17 through 6/13/17 in

=Sum({$ <Transactions.Txn Date={"$(='>=' & Date(YearStart(Max(Transactions.Txn Date)), 'MM/DD/YYYY') & '<=' & Date((Max(Transactions.Txn Date)), 'MM/DD/YYYY'))"}>} [Transactions.Amount])

for previous year

/1/16 through 6/13/16.

=Sum({$ <Transactions.Txn Date={"$(='>=' & Date(YearStart(Max(Transactions.Txn Date),-1), 'MM/DD/YYYY') & '<=' & Date(addyears(Max(Transactions.Txn Date),-1), 'MM/DD/YYYY'))"}>} [Transactions.Amount])

Not applicable
Author

Thank you both, this worked!