About
This use case introduces the custom condition query. While standard conditions are great for simple filtering, identifying "inactive" users requires a dynamic date calculation. This guide will show you how to use a small snippet of SQL logic to filter users based on a moving timeframe.
To access these settings, navigate to Site administration > Plugins > Local plugins > Dash Addons > Manage data sources and select Create custom data source.
1. General settings
Set up the identity for the user list.
Data source name: Inactive students
ID number: inactive-students
Select main table (mnt): user
Click the Generate fields button.
2. Fields setup
Define the columns for your report. Ensure you transform the last access timestamp into a readable date.
Placeholder fields: Select
user:id(mnt.id).Field #1
Field: user:firstname
Transform the format: None
Field #2
Field: user:lastname
Transform the format: None
Field #3
Field: user:lastaccess
Transform the format: Date
3. Condition setup
This is where the power of the custom query comes in. We want to find users whose last access was more than 30 days ago, but exclude those who have never logged in at all.
Enable conditions: Checked
Custom condition query:
mnt.lastaccess > 0 AND mnt.lastaccess < UNIX_TIMESTAMP(NOW()) - 2592000
Note: The number 2592000 represents 30 days in seconds (60 seconds $\times$ 60 minutes $\times$ 24 hours $\times$ 30 days).
How to use this data source
Once saved, add a Dash block to any page and select Inactive Students from the "Build your own" section. You can then open the block preferences and enable the fields you wish to display within the Fields tab.