Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
panwipa2528
Contributor III
Contributor III

How to code expression about YTD?

I need to compare year to date,

Now I do

for 2017 = Sum({$<Year = {$(#=(Year-1), Month=, Date=,)}, } Sales) >>> 1-15 Sep 2017

for 2016 = Sum({$<Year = {$(#=(Year-1), Month=, Date=,)}, } Sales) >>> 1-30 Sep 2016

but I need

for 2017 = Sum({$<Year = {$(#=(Year-1), Month=, Date=,)}, } Sales) >>> 1-15 Sep 2017

for 2016 = Sum({$<Year = {$(#=(Year-1), Month=, Date=,)}, } Sales) >>> 1-15 Sep 2016

9 Replies
PrashantSangle

Hi,

If you have date field

then try like

sum({<date={"=date(addYears(max(date),-1)))"}>}Sales)

Regards,

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
shraddha_g
Partner - Master III
Partner - Master III

Consider you have Date field in your Data Model &

Assume 2 Variable for From Date & To Date as vFromDate & vToDate respectively.

Then Try CY YTD 

sum( {<Date = {">=$(=vFromDate) <= $(=vToDate)"}>}Sales)

For LY YTD

sum( {<Date = {">=$(=date(addyears($(vFromDate),-1))) <=$(=date(addyears($(vToDate),-1)))"}>}Sales)

panwipa2528
Contributor III
Contributor III
Author

Thank you for you help. Your answer is correct, but I have a problem if I choose year and date as attach file,
It's not work. How should I do?

panwipa2528
Contributor III
Contributor III
Author

stalwar1‌ Help me pleaseeeeee

sunny_talwar

Try this for last year

Sum({<Date = {">=$(=Date(AddYears($(vFromDate),-1)))<=$(=Date(AddYears($(vToDate),-1)))"}, Year, Month>}Sales)

panwipa2528
Contributor III
Contributor III
Author

Can not . stalwar1‌

sunny_talwar

Can you explain in words as to what is the issue?

panwipa2528
Contributor III
Contributor III
Author

If I select
1. Month = September & Year = 2017 > Result will show summary all month (1-30 Sep 2016)
2. Period 1-15 September 2017 > Result will show summary 1-15 Sep 2016

But this expression it's work only 2. (Select Period), I need both condition.

Sum({<Year, Month, date_key = {">=$(=Date(AddYears($(vDateFrom),-1)))<=$(=Date(AddYears($(vDateTo),-1)))"}>}Fact_Tran.Qty)

PrashantSangle

can you provide sample app???

Regards,

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂