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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
amien
Specialist
Specialist

counter value within last 7 days

i have this table:

key, unique address, date, #counter

1, 100, 20160101, 1

2, 100, 20160102, 1

3, 100, 20160502, 1

i need this result in a straight table

dim_address, dim_date, expression

100, 20160101, 1

100, 20160102, 2  <---

100, 20160502, 1

<-- this record does a sum(#counter) but looks for the last 7 days. It therefor has a hit on 20160101 and shows 2.

What expression do i need for this? Point in time is not working in this case.

Thanks in advanced

1 Solution

Accepted Solutions
sunny_talwar

Which expression is moving in the right direction?

To solve your concerns for the 1st problem, you can use The As-Of Table‌ and to address second issue just in the expressions you can try something like this out:

2) RangeSum(Above(Sum({<Year, Month, Date>}Value), 0, 7)) * Avg(1)

3) If(WeekDay(Date) = 'Fri', RangeSum(Above(Sum({<Year, Month, Date>}Value), 0, 7)), Sum({<Year, Month, Date>}Value)) * Avg(1)

But I think based on what you are looking for, I would suggest using The As-Of Table approach because this will address both your issues at once.

View solution in original post

11 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

It would be great if you share some sample data.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
amien
Specialist
Specialist
Author

the sample data is in the first threat

sum(#counter) should give me the current one of the dimension + i need to sum(#counter) of the previous 7 days (if any), within the unique address

sunny_talwar

I think what kaushik.solanki‌ is looking for a more comprehensive example where is would be easier to see the logic. Would you be able to provide few more data points so that the logic becomes clearer. Also do you want this in the front end, or a script based solution can also work?

amien
Specialist
Specialist
Author

Fair Enough;

I uploaded an example (starting post). On the red line, a need the sum of the blue line in an expression. the blue line looks 7 days back within the same Dim (Street1). Front end solution is preferred.

2016-08-28_11-59-53.png

sunny_talwar

Are you looking for one of these solutions?

Capture.PNG

Expressions

1) Sum(Value)

2) RangeSum(Above(Sum(Value), 0, 7))

3) If(WeekDay(Date) = 'Fri', RangeSum(Above(Sum(Value), 0, 7)), Sum(Value))

effinty2112
Master
Master

Hi Amien,

                    Copy your expression and make it accumulate 7 steps back. The accumulation will reset when the value of Dim changes:

7day accum.jpg

Regards

Andrew

amien
Specialist
Specialist
Author

Yes and now

it will work only if all days have a record, which will not be the same. For specific days the fact might be missing.

Plus the 7 trick will only work on the current selection right? so if a user will select 2016, it will leave out the 31-12-2015 record right?

sunny_talwar

Which expression is moving in the right direction?

To solve your concerns for the 1st problem, you can use The As-Of Table‌ and to address second issue just in the expressions you can try something like this out:

2) RangeSum(Above(Sum({<Year, Month, Date>}Value), 0, 7)) * Avg(1)

3) If(WeekDay(Date) = 'Fri', RangeSum(Above(Sum({<Year, Month, Date>}Value), 0, 7)), Sum({<Year, Month, Date>}Value)) * Avg(1)

But I think based on what you are looking for, I would suggest using The As-Of Table approach because this will address both your issues at once.

sunny_talwar

Added the As-Of Table approach for you to play around with

Script:

t1:

LOAD

  %Datum_key,

  'Street 1' As Dim,

  Num(RAND()*10,'0') As Value

RESIDENT Calender;

Concatenate(t1)

LOAD

  %Datum_key,

  'Street 2' As Dim,

  Num(RAND()*10,'0') As Value

RESIDENT Calender;

AsOfTable:

LOAD Date(%Datum_key) as NewDim,

  %Datum_key - IterNo() + 1 as %Datum_key

Resident t1

While IterNo() <= 7;

Capture.PNG