Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
padmanabhv
Contributor III
Contributor III

Qliksense Button to toggle every 20th time stamp (subsampling the data)

Hello,
Lets say I have a large data set - with  data collected every 15 seconds - 00:00:15, 00:00:30
I also have timestamps number 1,2, etc corresponding with each timestamp
1 - 00:15
2- 00: 30 , etc

I need to sub-sample to every 20th sample, using a button and I cannot figure out the what to put under 'Value' within Button > actions > Togglefield selection ?
There has to be some formula using mod that should get me what I need.
Thank you for your help !!

Labels (3)
2 Replies
padmanabhv
Contributor III
Contributor III
Author

I put a hacky - '= '(1|21|41|61|81|101|121|141|161|181|201|221|241|261|281|301|321|341|361|381|401|421|441|461|481|501|521|541|561|581|601)' in the value box, to take in every 20th sample
But there has to be a more elegant way

Levi_Turner
Employee
Employee

My gut approach would be to off-load this to a counter in the script. That'll be far more maintainable and more performant.

Let's take a table which I mocked up:

[table]:
LOAD 
	RowNo() AS [Hour]
AutoGenerate 24;

LEFT JOIN([table])
LOAD
	RowNo() AS [Minute]
AUTOGENERATE 60;

LEFT JOIN([table])
LOAD
	RowNo() AS [Second]
AUTOGENERATE 60;

RENAME TABLE [table] TO [tmp];

[table]:
NoConcatenate
LOAD
	RowNo() AS [id],
    *
RESIDENT [tmp];

DROP TABLE [tmp];

 

From there, we can build a counter like so:

[table]:
NoConcatenate
LOAD
	*,
	if(Mod(Frac(([id]-1)/20),1)=0 OR [id]=1,1,0) AS [Counter];
LOAD
    [id],
    [Hour],
    [Minute],
    [Second]
RESIDENT [tmp];

DROP TABLE [tmp];

 

To walk through the counter,

  • Set 1 for the counter if the id = 1 (aka the first record)
  • For all subsequent records: 
    • Subtract 1 (i.e. 21 -> 20)
      • ([id]-1)
    • Divide  by 20 (i.e. 20 / 20)
      • ([id]-1)/20)
    • Take the fraction of that value (i.e, 20 / 20 = 1, fraction = 0)
      • Frac(([id]-1)/20)
    • Perform a modulo function on this value  (i.e 0 / 1 = 0)
      • Mod(Frac(([id]-1)/20),1)
    • If that return is 0 then evaluate as true, else it's false