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: 
aashok
Contributor III
Contributor III

Show last 2 year data in Qlik sense chart

Hi , I  am trying to show only the last 2 years data in qlik sense chart. but some how I am unable to write the expression correctly which I could get from the community.

aashok_1-1654072845341.png

 

aashok_0-1654072793145.png

Currently the expression shows all the year .I tried to change the expression as below.but it gives error. Could anyone help .

{<FY={$(=Max(Journal_Date.FiscalCalendar.FY)),$(=Max(Journal_Date.FiscalCalendar.FY)-1)}>}

 

Labels (2)
16 Replies
aashok
Contributor III
Contributor III
Author

@vinieme12 , I have pasted  below the fiscal calendar section. but here it is assigned numeric .

 

Calendar:
DECLARE FIELD DEFINITION TAGGED '$date'

Fields
Year($1) As Year Tagged ('$numeric'),
Dual('Q' & ceil(month($1)/3), ceil(month($1)/3)) As Quarter,
Month($1) as Month Tagged ('$numeric'),
Date(QuarterStart($1),'YYYY' & '-Q' & ceil(month($1)/3)) As [YYYY-Q],
Date(MonthStart($1),'MMM-YYYY') as [MMM-YYYY],
Week($1) as Week Tagged ('$numeric');

 


FiscalCalendar:
DECLARE FIELD DEFINITION TAGGED '$date'

Fields
Year(AddMonths($1,-3)) As [Fiscal Year] Tagged ('$numeric'),
'FY' & Date(QuarterStart(AddMonths($1,-3)),'YY') As [FY],
Dual('Q' & ceil(month(AddMonths($1,-3))/3), ceil(month(AddMonths($1,-3))/3)) As [Fiscal Quarter],
Month($1) as [Fiscal Month] Tagged ('$numeric'),
Date(QuarterStart(AddMonths($1,-3)),'YYYY' & '-Q' & ceil(month(AddMonths($1,-3))/3)) As [Fiscal YYYY-Q],
'FY' & Date(QuarterStart(AddMonths($1,-3)),'YY' & '-Q' & ceil(month(AddMonths($1,-3))/3)) As [YearQuarter],
Date(MonthStart($1),'MMM-YYYY') as [YearMonth],
Week(AddMonths($1,-3)) as [Fiscal Week] Tagged ('$numeric');


DERIVE FIELDS FROM FIELDS [Journal_Date] USING [Calendar];
DERIVE FIELDS FROM FIELDS [Journal_Date] USING [FiscalCalendar];

 

and in another page declaration done as 

Period:
Load * Inline [
Period, PeriodFieldName
Quarterly, Journal_Date.FiscalCalendar.YearQuarter
Monthly, Journal_Date.FiscalCalendar.YearMonth
Yearly, Journal_Date.FiscalCalendar.FY
];

Variance_table:
Load * Inline [
Variance_field
Surplus/(Deficit)
Income
Expenditure
Grant Income
];

vinieme12
Champion III
Champion III


Year(AddMonths($1,-3)) As [Fiscal Year] Tagged ('$numeric'),   <<-- This is a NUMERIC field
'FY' & Date(QuarterStart(AddMonths($1,-3)),'YY') As [FY],     <<-- This is a TEXT field

 

You can USE the [FY] as a dimension but cannot use it to do comparisons such as ><= or additions /subtractions as it is text

You need to use the NUMERIC  [Fiscal Year]  field for that

 

sum({<[Fiscal Year]={">=$(=Max([Fiscal Year],2)"}>} somemeasure)

or

sum({<[Fiscal Year] ={">=$(=Max([Fiscal Year],2)<=$(=Max([Fiscal Year])"}>} somemeasure)

or

sum({<[Fiscal Year] ={'$(=Max([Fiscal Year],2)','$(=Max([Fiscal Year])'}>} somemeasure)

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

@vinieme12  thanks again.

have 2 more doubts to clarify.

As you mentioned, I am using the Fiscal Year(numeric) now  , in my script , it becomes Journal_Date.FiscalCalendar.Fiscal Year.


sum({<[Journal_Date.FiscalCalendar.Fiscal Year] ={">=$(=Max([Journal_Date.FiscalCalendar.Fiscal Year],2)<=$(=Max([Journal_Date.FiscalCalendar.Fiscal Year])"}>} classification)

The second and third fiscal year used in the expression does not seem to be a field .

The measure used in my case seems to be in a different manner . So I am not sure how to use it inside the expression.I have attached the screenshots below.

aashok_0-1654480147275.png

aashok_1-1654480184607.png

aashok_2-1654481341351.png

 

Is there any suggestion that you could advise?

vinieme12
Champion III
Champion III

just copy paste the below in your current set, i was missing some brackets above

 

[Journal_Date.FiscalCalendar.Fiscal Year] ={">=$(=Max([Journal_Date.FiscalCalendar.Fiscal Year] ,2))<=$(=Max([Journal_Date.FiscalCalendar.Fiscal Year] ))"}

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

@vinieme12 

thanks again for your patience. Why does it show the garbage after expression. If I use the journal.date.fiscalcalendar.fiscal Year alone it works but with the expression , it give error as shown below.

aashok_0-1654489064422.png

 

 

vinieme12
Champion III
Champion III

this is working fine, but you need to add in in your current expression!!

example

=sum({<

Classification={'SBU'}

,Account_Code-={'6*','7*','8*'}

,[Journal_Date.FiscalCalendar.Fiscal Year] ={">=$(=Max([Journal_Date.FiscalCalendar.Fiscal Year] ,2))<=$(=Max([Journal_Date.FiscalCalendar.Fiscal Year] ))"}

>}[Deficit Surplus])

 

 

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

@vinieme12 , finally resolved it. thanks again for your help.