Toucan 3.0
YouPrep documentationHelp centerGet a demo
  • Welcome
    • ๐Ÿ‘‹Welcome to Toucan
    • โš™๏ธTechnical resources
      • โš™๏ธToucan stack
      • Setup mode
        • Toucan SaaS mode
      • โš™๏ธSecurity
        • Application Security
        • Source Code Quality
        • Global Security Practices
        • Security of Docker Images
  • TUTORIALS
    • ๐Ÿ“ŠGetting Started : Embedded Analytics
    • ๐Ÿค“Advanced tutorials
      • Embedding a story with user attributes
        • Dynamic filter with user attributes
        • Dynamic Tables
        • Dynamic Database
        • Dynamic Host
      • Using the HTTP API connector in advanced use cases
      • Using advanced syntax for SQL queries
      • Merging filters with our tool
      • Deep customization chart (CSS)
        • Homepage customization
        • Chart customization
        • Dashboard customization
  • Data Management
    • ๐ŸงฎOverview of Data In Toucan
    • ๐Ÿ“กDatasources in Toucan
      • ๐Ÿ”ŒManaging Connectors
        • ๐Ÿ”ŒCreating, editing and deleting a connector
        • ๐Ÿ”ŒSet up OAuth2 credentials for your platform
        • ๐Ÿ”ŒSetting up a connector
          • ๐Ÿ”ŒGeneric Connectors
            • ๐Ÿ”ŒSetting up an HTTP API connector
            • ๐Ÿ”ŒSetting up an ODBC Connector
          • ๐Ÿ”ŒDatabase and data warehouse Connectors
            • ๐Ÿ”ŒSetting up an AWS Redshift Connector
            • ๐Ÿ”ŒSetting up a Snowflake Connector
            • ๐Ÿ”ŒSetting up a PostgreSQL Connector
            • ๐Ÿ”ŒSetting up a Google Big Query Connector
            • ๐Ÿ”ŒSetting up an AWS Athena connector
            • ๐Ÿ”ŒSetting up a MySQL connector
            • ๐Ÿ”ŒSetting up a MongoDB connector
            • ๐Ÿ”ŒSetting up a Microsoft SQL Server connector
            • ๐Ÿ”ŒSetting up an Azure SQL connector
            • ๐Ÿ”ŒSetting a Databricks Connector
            • ๐Ÿ”ŒSetting up a ElasticSearch Connector
            • ๐Ÿ”ŒSetting up a Clickhouse Connector
          • ๐Ÿ”ŒOnline services connectors
            • ๐Ÿ”ŒSetting up a Sharepoint Connector
            • ๐Ÿ”ŒSetting up a Google Sheets Connector
            • ๐Ÿ”ŒSetting up a Salesforce Connector
            • ๐Ÿ”ŒSetting up a Hubspot Connector
          • ๐Ÿ”ŒSetting up an AWS S3 connector
      • ๐Ÿ—„๏ธManaging remote file storages
        • ๐Ÿ—‚๏ธSetting up a file storage
          • SFTP
        • ๐Ÿ“„Create a dataset from a file
      • ๐Ÿ“Managing Files
        • ๐Ÿ“Adding, editing and deleting local files
        • ๐Ÿ“‚Using advanced file settings
        • ๐Ÿ“Adding and combining remote files in Toucan
    • ๐Ÿ”ขDatasets in Toucan
      • ๐Ÿ”ขStored and Live Datasets
      • ๐Ÿ’ฟManaging datasets
        • ๐Ÿ”ขCreating datasets
        • ๐Ÿ”ขEditing, Duplicating and Deleting a dataset
        • ๐Ÿ”ขRefreshing and Publishing Datasets
        • ๐Ÿ“ˆOptimize data performance
        • ๐Ÿ—‚๏ธAdding indexes to stored datasets
        • ๐Ÿ‘ฉโ€๐Ÿ’ปCode mode and single mode
      • ๐Ÿ›‘Setting permissions on dataset
      • ๐Ÿ—ƒ๏ธMaintaining Data
        • ๐Ÿ—ƒ๏ธTagging datasets
        • ๐Ÿ—ƒ๏ธIdentifying datasets dependencies
        • ๐Ÿ—ƒ๏ธSet validation rules
    • ๐Ÿง‘โ€๐ŸณPreparing data
      • Overview of YouPrepโ„ข
        • ๐ŸŽนColumn header
          • Rename column
          • Duplicate column
          • Fill null values
          • Replace values
          • Sort values
          • Convert columns data types
        • Add
          • Add text column
          • Add formula column
          • Add conditional column
        • Filter
          • Delete columns
          • Keep columns
          • Filter rows
          • Top N rows
          • ArgMax
          • ArgMin
        • Aggregate
          • Group by
          • Add total rows
          • Hierarchical rollup
          • Get unique groups/values
        • Compute
          • Compute evolution
          • Cumulated sum
          • Percentage of total
          • Rank
          • Moving average
          • Compute statistics
          • Absolute value
        • Text
          • Concatenate
          • Split column
          • Extract substring
          • To lowercase
          • To uppercase
          • Compare text columns
          • Trim spaces
          • Replace text
        • Date
          • Convert text to date
          • Convert date to text
          • Extract date information
          • Add missing dates
          • Compute duration
          • Normalize date granularity
        • Reshape
          • Pivot
          • Unpivot
          • Waterfall
        • Combine
          • Append datasets
          • Join datasets
        • Geo
          • Geographic dissolve
          • Geographic hierarchy
          • Geographic simplify
          • Prepare geo data (with basemap)
      • YouPrepโ„ข Native SQL
      • Hybrid pipeline
    • โžฟManaging variables in Toucan
      • โžฟVariables hub
      • โ™ˆUse variables in YouPrepโ„ข
      • โžฟEasy reference to variables
    • ๐ŸงžUsing advanced data concepts
      • ๐ŸงžData personnalisation with user attributes
        • Connector setup with a user attribute
        • Database selection with a user attribute
        • YouPrep data filtering with a user attribute
        • Filter data in SQL with a user attribute
      • ๐ŸงžAdvanced syntax for variables
      • ๐ŸงžData cache
  • Visualizations and Layouts
    • ๐Ÿ“บApps
      • ๐Ÿ“บManaging Apps
        • โž•Creating Apps
        • ๐Ÿ“„Duplicating Apps
        • ๐Ÿ–จ๏ธPublishing Apps
        • ๐ŸšฎDeleting Apps
        • โœ๏ธEditing within an App
      • ๐Ÿ–Œ๏ธCustomizing Apps
        • Customizing chart color elements
        • Customizing the app's font
        • Adding Assets
        • Adding Glossary
        • Setting up, Managing and testing custom visibilities
        • Customizing the "no data error" message
        • Creating a dynamic background based on an Filter's column
      • ๐Ÿ Home
        • Creating the Home
        • Creating Tiles
          • Tile Dynamic Value
          • Tile Leaderboard
          • Tile Line
          • Tile Scorecard
          • Tile Bullet
          • Tile Heatmap
          • Tile PDF
          • Tile Video
          • Tile Image
          • Tile Text
          • Tile HTML
          • Tile Separator
      • โœจStories
        • Creating a Story
        • KPIs
        • Narrative
        • Crossfilter
      • ๐Ÿ“ฝ๏ธFilters
        • Managing Filters
          • Creating, reusing and editing Filters
          • Applying Filters
          • Unpinning and deleting Filters
        • Type of Filters
          • Dropdown
          • Checkboxes
          • Buttons
          • Date Range
          • Hierarchical
          • Slider
        • Templating from Filters' values
        • Dependant Filters
      • ๐Ÿ“ˆPDF Report
      • ๐ŸŽกDatawall
      • ๐Ÿ—๏ธDashboard Builder
        • Create a Dashboard Builder
        • Embed a Dashboard Builder
        • Dashboard export options
      • ๐ŸŒŸMyFavorites
    • ๐Ÿ“ŠCreating Visualizations
      • ๐ŸคฉViz Gallery
        • โœจNew Viz Designs
          • Barchart
          • Barlinechart
          • Bubblechart
          • Circularchart
          • Heatmap
          • Leaderboard
          • Linechart
          • Stacked Barchart
          • Tablechart
        • ๐Ÿ“Legacy Viz Designs
          • Bulletchart
          • Funnelchart
          • Gantt chart
          • HTML
          • Leaderboard Centered Average
          • Mapchart
            • Configure a drill
          • Mediachart
          • Radarchart
          • Timeline
          • Versuschart
          • Waterfallchart
          • Score Card
      • ๐Ÿง Common Chart Configuration
      • ๐Ÿ’…Customizing chart colors
      • ๐Ÿงžโ€โ™‚๏ธAdvanced chart configuration
        • Templating from chart's dataset
        • Add units, precisions and sentiments
        • Adding Tutorials
        • Add sparklines
        • Navigate with stories
        • Group informations in your stories
        • Multiple charts in one story
        • Manage dates
        • Customize tiles' sources
        • Add stars to tiles' title
        • Manage data order in your tiles
        • Navigate with tiles
    • ๐Ÿ‘ฉโ€๐Ÿ’ปEmbedding
      • ๐Ÿ”Authentication
      • ๐Ÿ–‡๏ธIntegration
        • Generate and manage embeds
        • Customize embeds
        • Embedding a Toucan App Using iFrames
        • Passing Extra Variables to Your Toucan Embed
      • โš™๏ธEmbed SDK
        • Embed SDK Authentication
      • โ“FAQ
    • ๐Ÿ™‹Self-Service
      • Self-Service Dashboard
        • The embedded Self-Service Dashboard
        • The in-platform Self-Service Dashboard
      • Self-service PDF Report
  • Collaboration
    • โฐCreating alerts
    • ๐Ÿ“งManaging notifications
    • โž•Enriching a story with descriptions
    • ๐Ÿ’ŒSharing content
    • ๐Ÿ’ฌAdding comments to stories
  • Administration
    • โš™๏ธInstance Management
      • โš™๏ธManaging operations in SaaS
      • โš™๏ธCustomizing your instance (whitelabel)
    • ๐Ÿ‘ฅManaging Users
      • ๐Ÿ‘ฅUsers
      • ๐Ÿ‘ฅManaging user groups
      • ๐Ÿ‘ฅManaging user properties
      • ๐Ÿ‘ฅSetting up permissions and visibilities
    • ๐ŸŒManaging languages in Toucan (internationalisation)
    • ๐Ÿ“ˆMonitoring Engagement with User Analytics
      • ๐ŸŽ›๏ธHow to Filter your User Analytics?
      • ๐Ÿ–ฅ๏ธUnderstanding your User Analytics Dashboards
  • Additional Ressources
    • ๐Ÿ“šExternal documentation
    • ๐ŸšSupport for App-builders
    • ๐Ÿ†•Latest releases
      • ๐ŸŽ2025 Releases
      • ๐ŸŽ2024 Releases
      • ๐ŸŽ2023 Releases
    • ๐Ÿ”งTroubleshooting
      • Troubleshoot:: DataHub
      • Cross-Site Cookies
      • How to :: read the inspector error
      • How to :: troubleshoot the toucan way
Powered by GitBook
On this page
  • Whatโ€™s the difference between โ€˜{{ }}โ€™ & โ€˜<%= %>โ€™ syntaxes?
  • Filters
  • User attributes
  • Extra Variables
  • Language Variables
  • Chart Data
  • User Group
  • Relative Dates

Was this helpful?

  1. Data Management
  2. Using advanced data concepts

Advanced syntax for variables

Last updated 10 months ago

Was this helpful?

Whatโ€™s the difference between โ€˜{{ }}โ€™ & โ€˜<%= %>โ€™ syntaxes?

Variable values to be interpolated can be injected from 2 different sources:

  • The user interface (front-end): these are variables that could be set by the App-builder and/or Viewer when editing the app configuration through the studio or when dealing with filters. These kinds of variables are injected by using the '<%= ... %>' syntax. This syntax is executed as Javascript code.

  • Toucan's backend: these are variables coming from Toucan's instance configuration (for example instance name), or the user's attributes. These kind of variables are injected by using the {{ ... }} syntax.

Filters

In some configuration interfaces, you might need to use manually use our syntax to refer to a filter value, for a more advanced usage. This can be done with the syntax below (the FILTER_ID is accessible within the filter's configuration interface).

<%= filters["FILTER_ID"]["COLUMN_NAME"] %>

More detail on templating from the filter's value .

All option in filters (__VOID__)

By default, the filters created are using the "All" option that allows to not apply the filtering. All option refers to the variable value "__VOID__" used as a kind of identifier to not apply the filter when the variable is used in YouPrep.

The case of date range filters

Date Range filters are special as when we choose the dataset's column, it's not from where we're fetching data. Also, as a range, it exposes a start and end date. Here's how to use them:

Start:

<%= filters["FILTER_ID"]["start"] %>

End:

<%= filters["FILTER_ID"]["end"] %>

Advanced use date of date filters

Variable from data range filters are expressed within ISO-8601 format with date and time as the following date: 2023-02-02T00:00:00.000Z

For different cases (data querying, display, ...), you might only need the date part (2023-02-02).

In order to extract the date part, you can use the templating syntax below (example for start date):

<%= filters["FILTER_ID"]["start"].toISOString().split('T')[0] %>

Advanced use case with management of __VOID__ in SQL

For some advanced use cases, when creating a dataset from a connector, you can make the choice to make some data transformation/filtering directly into SQL and refer to the variable with the syntax above. However, when the filter uses the option "All", the variable will take the value "__VOID__" that won't be interpreted by your database. Thus, you might condition the application of the filter.

Here is an example (where 4171d27a-f8dc-4c91-8c43-c750aa1eee95 is corresponding to the filter's ID, and company to the column name used by the filter) of a complete SQL query that includes WHERE conditions in order to filter the data.

SELECT * from my_table WHERE 
CASE
    WHEN <%= filters["4171d27a-f8dc-4c91-8c43-c750aa1eee95"]["company"] %> = '__VOID__' 
        THEN true
    ELSE
        company = <%= filters["4171d27a-f8dc-4c91-8c43-c750aa1eee95"]["company"] %>
END

Advanced use case with management of __VOID__ in storytelling

When being within the storytelling part, you can refer to the filter value (within narrative, section title, text tile, ...) in order to personalize the experience and facilitate informations interpretation. However the the actual selected value is corresponding to __VOID__ , you might want to display a more meaningful label. This can be done with the syntax below:

<%= filters["FILTER_ID"]["COLUMN_NAME"] === 'VOID' ? 'label_for_All' : filters["FILTER_ID"]["COLUMN_NAME"] %>

Advanced use case of list

Depending the the configuration of the filter, it can retrieve a list of values (for example the "checkbox" type) and not just one value. Thus in order to display the value in a customized way, the function join can be used in order to separate each value of the list by a custom char:

<%= filters["4171d27a-f8dc-4c91-8c43-c750aa1eee95"]["companies"].join(', ' ) %>

User attributes

At different configuration interfaces (connector settings, query setting, YouPrep, ...) you get to refer to user attributes, in order to personalize the experience depending on the user. In the example below, we refer to the user attribute named "database_name_attribute"?

{{ user.attributes.database_name_attribute }}

In some cases, we need to use a more complex syntax, in order to use a default value when the user attribute doesn't exist. In the example above, the syntax is referring to a user attribute named "database_name_attribute", and uses by default 'database_name_default' if the user attribute doesn't exist.

{{ (user or {}).get('attributes', {}).get('database_name_attribute', 'database_name_default') }}

Note that, if you want to display the value of a user attribute, within a narrative, tile, or home section title, you must use the <%= ... %> syntax like in the example (with country variable) below:

<%= user["attributes"]["country"] %>

Extra Variables

Extra Variables correspond to variables coming from an external environment (sent through Toucan SDK). You can refer to an extra variable by using the syntax below.

<%= extraVariables["my_variable"] %>

In some cases, we need to use a more complex syntax, in order to use a default value when the extraVariable doesn't exist within the context. In the example below, we refer to the extraVariable 'my_variable' if it exists, else we use by default the value 'my_default_value'.

<%= extraVariables["my_variable"] ?? 'my_default_value' %>

Language Variables

At different levels of the app (YouPrep, narrative, titles, ...), you can refer to language variables in order to personalize the end-user experience according the language preference. You can refer to a variable (defined in the dictionary of translation) with the syntax below:

<%= lang["ELEMENT_TO_TRANSLATE"] %>

You can also refer to the variable containing the value of the language preference with the syntax below:

<%= locale %>

Chart Data

When being in a story, it's possible to refer to the first value of a specific column in the data used by the chart, for example in order to give contextualized data within your narrative. This can be done with the syntax below (knowing that the content between data brackets corresponds to the chart ID, which can be found in the chart configuration interface).

<$= data["4c7274d9-bae4-e77c-d1ef-21ddd98dee0c"]["my_column"] $>

However, when referring to a column resulting from an aggregation made through the SmartEditor, the column ("my_column") to which you have to refer to follows this format: __aggregType_myColumn__.

So for example, when referring to a column "profit" aggregated with the sum operator, the syntax to use will be:

<$= data["4c7274d9-bae4-e77c-d1ef-21ddd98dee0c"]["__sum_profit__"] $>

Here is the list of the different aggregation prefixes: sum (for sum), avg (for average), min (for minimum), max (for maximum), first (for first), last (for last), count (for count), count distinct (for Count Distinct).

User Group

At different configuration interfaces (connector settings, query setting, YouPrep, ...) you can refer to user attributes, in order to personalize the experience depending on the user. The example below shows how to call the variable through the back-templating syntax.

{{ user.groups }}

Note that, if you want to display the value of a user attribute, within a narrative, tile or home section title, you must use the <%= ... %> syntax like in the example (with country variable) below:

<%= user["groups"] %>

Syntax to use depending on the location:

  • {{ ... }} : connector, connector query

  • <%= ... %> : narrative, tiles

The user variable "groups" retrieves a list of values (groups)

Relative Dates

You can refer to relative dates defined automatically within Toucan. Here is the list of available variable.

  • Today: <%= dates.today %>

  • Yesterday: <%= dates.yesterday %>

  • The actual week monday: <%= dates.thisWeekMonday %>

  • The last week monday: <%= dates.lastWeekMonday %>

  • The first day of the month: <%= dates.thisMonth %>

  • The first day of the last month: <%= dates.lastMonth %>

  • The first day of this quarter: <%= dates.thisQuarter %>

  • The first day of the last quarter: <%= dates.lastQuarter %>

  • The first day of this semester: <%= dates.thisSemester %>

  • The first day of the last semester: <%= dates.lastSemester %>

  • The first day of the year: <%= dates.thisYear %>

  • The first day of the last year: <%= dates.lastYear %>

More detail on language and translation .

More detail on chart dataset templating .

You can easily refer to those variables within YouPrep without using any syntax. More about it .

๐Ÿงž
๐Ÿงž
here
here
here
here