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: 
Anonymous
Not applicable

Last 6 sales but dates are not sequential

Hi

I have data as below and want to show last 6 transdate sales in bar char. Since my dates are not sequential i cannot put Max(date)-5.

I have applied formula sum({<StatDt={">=$(=Max(StatDt,5))"}>}Sales) but when i make selection in StatDt field i am getting error message that "No Data to Display" in chart

Please suggest new formula in front end to fix.

Note (i can fix it by script in using autonumber function)

  

StatDt Sales
2/29/201665
3/12/20165
3/26/201610
4/5/201615
4/12/201620
4/28/201625
5/1/201630
5/10/201635
5/29/201640
6/20/201645
7/26/201650
11/10/201655
2/25/201760
5/10/201770
5/15/201775
5/30/201780

Regards

ramu

5 Replies
boorgura
Specialist
Specialist

if you make a selection in StartDt --> then there would be no valid value for max(StartDt, 5) - unless you select 5 or more dates.

If you want top 5, irrespective of selections - then use max({1} StartDt, 5)

sunny_talwar

Try this:

Sum({<StatDt={">=$(=Max({<StatDt = {'<=$(=Max(StatDt))'}>}StatDt,5))<=$(=Max(StatDt))"}>}Sales)


Capture.PNG

Anonymous
Not applicable
Author

Thanks Sunny it is working. Can you please explain how it is evaluating in QV. especially this portion Max({<StatDt = {'<=$(=Max(StatDt))'}>}StatDt,5) why did you mention {'<=

effinty2112
Master
Master

Hi Ramu,

If you want to look at data for the last 6 dates loaded the expression in this table will do the trick.

cheers

Andrew

StatDt if(FieldIndex('StatDt',StatDt)>FieldValueCount('StatDt')-6,Sum(Sales))
26/07/201650
10/11/201655
25/02/201760
10/05/201770
15/05/201775
30/05/201780
sunny_talwar

The issue is that as soon as you select a single date, the Max(Date, 5) become null because there is only one date and max(date, 5) is looking for the 5th maximum date. By adding {<StatDt = {'<=$(=Max(StatDt))'}>}, I told the expression to look at all the date before the max date selected and find the max(date, 5) from that list.

Does this make sense?