Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Talend Cloud AWS EU Scheduled Outage: Starting Tues 26 May 21:00 CEST with expected completion Wed 27 May 01:00 CEST
cancel
Showing results for 
Search instead for 
Did you mean: 
cedfoning
Creator
Creator

Year to date & Month to date

Hello, 
I have an issue, 

i have the following table : 

cedfoning_0-1652389007795.png

I am new to Qlik and i want to have the following calculated files : 

1)YTD, 

2) Sum of amount for the since the beginning of the year 2022 (without the Yearmonth 202205)

3) Last year YTD

It will be helpful if anybody can help

@Taoufiq_Zarra 

Labels (3)
2 Solutions

Accepted Solutions
vinieme12
Champion III
Champion III

As below

2) Sum of amount for the since the beginning of the year 2022 (without the Yearmonth 202205) ,, not sure can you confirm exactly what you need

Then use the flags in your expressions 

YTD - Current YEar = sum({<YTD_currentYear={1}>}Amount)

YTD - Last YEar = sum({<YTD_lastYear={1}>}Amount)

 

Fact:
Load *,monthstart(date#(YrMnth,'YYYYMM')) as tDate Inline [
YrMnth,Amount
202201,1298
202202,1276
202203,934
202204,890
202205,1750
202101,2965
202102,1022
202103,1580
202104,1222
202105,1101
202106,2750
202107,265
202108,1783
202109,488
202110,2390
202111,630
202112,2520
];

 

Calendar:
Load
TempDate as tDate
,InYearToDate(TempDate, maxdate,0,1)*-1 as YTD_currentYear
,InYearToDate(TempDate, maxdate,-1,1)*-1 as YTD_lastYear
;
LOAD
date(MonthStart(mindate ,IterNo()-1)) AS TempDate
,maxdate
WHILE monthstart(mindate , IterNo()-1) <= maxdate;
LOAD
date(min(FieldValue('tDate', recno()))) as mindate
,date(max(FieldValue('tDate', recno()))) as maxdate
AUTOGENERATE FieldValueCount('tDate');

exit Script;

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

vinieme12
Champion III
Champion III

you are making selections in the wrong field, the YEARMONTH  field values 202201,202202....  is associated to the year 2022 data, so effectively you are filtering out the data

if you want to compare same months for current and previous year, you need to make selections in the MONTH field

Make selections in the  Month field (Jan,Feb etc..)  this will work

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

11 Replies
vinieme12
Champion III
Champion III

As below

2) Sum of amount for the since the beginning of the year 2022 (without the Yearmonth 202205) ,, not sure can you confirm exactly what you need

Then use the flags in your expressions 

YTD - Current YEar = sum({<YTD_currentYear={1}>}Amount)

YTD - Last YEar = sum({<YTD_lastYear={1}>}Amount)

 

Fact:
Load *,monthstart(date#(YrMnth,'YYYYMM')) as tDate Inline [
YrMnth,Amount
202201,1298
202202,1276
202203,934
202204,890
202205,1750
202101,2965
202102,1022
202103,1580
202104,1222
202105,1101
202106,2750
202107,265
202108,1783
202109,488
202110,2390
202111,630
202112,2520
];

 

Calendar:
Load
TempDate as tDate
,InYearToDate(TempDate, maxdate,0,1)*-1 as YTD_currentYear
,InYearToDate(TempDate, maxdate,-1,1)*-1 as YTD_lastYear
;
LOAD
date(MonthStart(mindate ,IterNo()-1)) AS TempDate
,maxdate
WHILE monthstart(mindate , IterNo()-1) <= maxdate;
LOAD
date(min(FieldValue('tDate', recno()))) as mindate
,date(max(FieldValue('tDate', recno()))) as maxdate
AUTOGENERATE FieldValueCount('tDate');

exit Script;

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
cedfoning
Creator
Creator
Author

Hello, thanks for your reply 

for the second question, I want : 

 

2) Sum(amount) for 2022, but without the amount of the Yearmonth 202205)

and for the 3rd question, the exact same, but for the year 2021

 

thanks

vinieme12
Champion III
Champion III

just modify the below, that's all

 

,InYearToDate(TempDate, maxdate,0,1)*-1 as YTD_currentYear

,InYearToDate(TempDate, addmonths(maxdate,-1),0,1)*-1 as YTD_exceptlatestMonth

,InYearToDate(TempDate, maxdate,-1,1)*-1 as YTD_lastYear

,InYearToDate(TempDate,addmonths(maxdate,-1),-1,1)*-1 as YTD_lastYearexceptLatestMonth

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
cedfoning
Creator
Creator
Author

Hello, 
i have another issue

Now, i want to analyse only the month of may of each year.
How can i do that ? 

Thanks

vinieme12
Champion III
Champion III

Dimension = Year

Measure

=sum({<Month={"=$(=Month(Max(Datefield)))"}>}Amount)

 

https://community.qlik.com/t5/Qlik-Design-Blog/Dates-in-Set-Analysis/ba-p/1472511

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
cedfoning
Creator
Creator
Author

thanks for your reply, 

it does not work
it shows me the values for all the year, not for the month only. 

vinieme12
Champion III
Champion III

Can you post a screenshot of the expression editor and also confirm the format of the Month field

refer the below link, 

 

Sum( {$<Month={"$(=Date(Max(Month),'MMM-YY'))"}>} Amount )

change format MMM-YY to match your month field

https://community.qlik.com/t5/Qlik-Design-Blog/Dates-in-Set-Analysis/ba-p/1472511

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
cedfoning
Creator
Creator
Author

Hello, the need is as follow : 

if i filter on the month of april, i want to have the values from january to april for each year. 

if i filter on the month of may, i want to have values from january to may for each year. 

 

Is it possible ? 

 

vinieme12
Champion III
Champion III

 

As below

Current year YTD

Sum( {<Datefield={">=$(=Date(yearstart(Max(Datefield)),'YYYY-MM-DD')<=$(=Date(Max(Datefield),'YYYY-MM-DD')"}>} Amount )

 

PRevious year YTD

Sum( {<Datefield={">=$(=Date(yearstart(Max(Datefield),-1),'YYYY-MM-DD')<=$(=Date(addyears(Max(Datefield),-1),'YYYY-MM-DD')"}>} Amount )

 

replace Datefield with the date field name in your app

also replace  YYYY-MM-DD with the date format of the date field as in your app

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.