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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Dislpaying Random Tips

Here is a fun little object I'm trying to implement into my template .qvw but I need a little help figuring something out. I have a simple spreadsheet that I am loading as a data island that contains small, simple tips for users. It's only two columns: a Tip_ID (integer starting at 1) and Tip_Text (usually no more than about 200 characters). Right now I have about 20 records but this will grow over time.


I want to display a text box on the opening sheet that displays a random tip from this loaded data. The tip displayed will change, randomly, every time the app opens. I'm also thinking of adding a button that the user can click on to display a new random tip (generate a new random number), just in case the the user wants to view other tips. But this latter feature is not required. The function for randomly choosing which tip to display needs to work between 1 and the max of the rows loaded from this spreadsheet. This app is ajax only, so a macro isn't a option. Any ideas?

1 Solution

Accepted Solutions
MarcoWedel

6 Replies
Not applicable
Author

You can generate a random number between 1 and x (where x is the number of records in your tip table) by doing the following:

floor(rand()*X+1)

To improve upon this, you could create a variable named say vNum. Create a button with an action to set the value of vNum equal to rand(), then use this equation:

floor(vNum*X+1)

Then put this into a textbox:

concat({<tip_id = {$(=floor(vNum*X+1)}>} tiptext)

MarcoWedel

Maybe an on open trigger selecting a value

Ceil(Rand()*Max({1} Tip_ID))

and then just displaying a text box with the actual tip text should do.

hope this helps

regards

Marco

Anonymous
Not applicable
Author

Actually, this seems to have worked: =Ceil(rand()*Max(Tip_ID))

Unless there is mathimatical flaw with that method that I don’t see.

- Brian

Anonymous
Not applicable
Author

Thanks for the input guys. This seems to be working:

vRandomTip: =Ceil(rand()*Max(Tip_ID))

List Box Expression: =If(Tip_ID=$(vRandomTip),[Tip Text])

MarcoWedel

QlikCommunity_Thread_144705_Pic1.JPG.jpg

QlikCommunity_Thread_144705_Pic2.JPG.jpg

Anonymous
Not applicable
Author

Nice Marco! I'll have to try that in the ajax client though since I've had issues with the OnOpen trigger not working.