Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
priyarane
Specialist
Specialist

Last 5 Days

Hi Experts,

How to find last 5 days depending selection.

For Ex: I have below data.

  

Tr_DateSales
01-05-201510
02-05-201523
03-05-201534
04-05-201555
05-05-201512
06-05-201511
07-05-201522
08-05-201533
09-05-201545

Filter is Tr_ Date

Straight table: Dim - Tr_Date, Expression - ?

so If I select Tr_Date-6th then I need 2 to 6 sales.

1 Solution

Accepted Solutions
sunny_talwar

Created a variable vVar = ='>=' & Date(Max(Tr_Date) - 4, 'DD-MM-YYYY') & '<=' & Date(Max(Tr_Date), 'DD-MM-YYYY')

and use this as your expression: =Sum({<Tr_Date = {'$(vVar)'}>}Sales)

Also find attached the application.

Best,

Sunny

View solution in original post

13 Replies
sunny_talwar

Use this in your set analysis:

{<Tr_Date = {">= $(=Date(Max(Tr_Date) - 4, 'DD-MM-YYYY')) <= $(=Date(Max(Tr_Date), 'DD-MM-YYYY'))"}>}

I think -4 should work to reach 2nd May, but if not try it with -5.

Best,

Sunny

prabhas277
Creator
Creator

Hi priya,

pls try the below expression if it works fine then give me correct answer

=sum({<Tr_Date={">=$(=max(Tr_Date))<=$(=max(Tr_Date)+4)"}>}Sales)

Regards,

prabhas

priyarane
Specialist
Specialist
Author

Hi Prabhas,

Its not working I am attaching my app

priyarane
Specialist
Specialist
Author

Hi SunIndia,

Its not working I am attaching my app

sunny_talwar

Created a variable vVar = ='>=' & Date(Max(Tr_Date) - 4, 'DD-MM-YYYY') & '<=' & Date(Max(Tr_Date), 'DD-MM-YYYY')

and use this as your expression: =Sum({<Tr_Date = {'$(vVar)'}>}Sales)

Also find attached the application.

Best,

Sunny

petter
Partner - Champion III
Partner - Champion III

A tweaking of SunIndia's suggestion should work for you:

     Sum( {<Tr_Date = {"<=$(=Date(Num(Max(Tr_Date))))>$(=Date(Max(Tr_Date)-4)))"}>} Sales)

Leaving out the formatting parameter for the Date() function will default to the formatting of dates that is currently active for your settings on your computer.

prabhas277
Creator
Creator

please attach your application then it will very clear

sunny_talwar

I was having a hard time understanding why the formula wasn't working. Petter Skjolden‌ do you know why the date formatting was creating a problem??

Best,

Sunny

maxgro
MVP
MVP

Sum( {$ <Tr_Date = {">=$(=Date(Max(Tr_Date)-4))<=$(=Date(Max(Tr_Date)))"}>} Sales)

1.png