support.coginiti.co Open in urlscan Pro
104.16.53.111  Public Scan

Submitted URL: https://email.coginiti.co/e3t/Ctc/ZS*113/cChL-04/VWB_9Y3X_1NnV3kdVB66t40VW9ccHTJ4Sc41lN8Vtb7G3lLBGV1-WJV7CgRHFW5kC8YW3xjNv...
Effective URL: https://support.coginiti.co/hc/en-us/articles/5829167701143-Macros/?utm_medium=email&_hsmi=233387969&_hsenc=p2ANqtz-9ddlO6sZ...
Submission: On November 10 via api from US — Scanned from DE

Form analysis 1 forms found in the DOM

GET /hc/en-us/search

<form role="search" class="search" data-search="" data-instant="true" autocomplete="off" action="/hc/en-us/search" accept-charset="UTF-8" method="get" data-hs-cf-bound="true"><input name="utf8" type="hidden" value="✓" autocomplete="off"><input
    type="search" name="query" id="query" placeholder="Search" autocomplete="off" aria-label="Search"></form>

Text Content

This website stores cookies on your computer. These cookies are used to collect
information about how you interact with our website and allow us to remember
you. We use this information in order to improve and customize your browsing
experience and for analytics and metrics about our visitors both on this website
and other media. To find out more about the cookies we use, see our Privacy
Policy

If you decline, your information won’t be tracked when you visit this website. A
single cookie will be used in your browser to remember your preference not to be
tracked.

Accept Decline
Skip to main content
Coginiti Home Submit a request Sign in Download
 1. Coginiti Support Home
 2. CoginitiScript
 3. Language Reference


 * Installing
   * Overview
     * End User License for Coginiti
     * Coginiti Version Numbers
     * Managing JDBC Drivers
     * Coginiti Pro Licensing Portal Overview
   * Coginiti Pro
     * Upgrade Process for Coginiti Pro
     * Installing Coginiti Pro on Microsoft Windows
     * Installing Coginiti Pro on macOS
     * MSI Installer for Coginiti Pro on Microsoft Windows
     * Coginiti Pro Licensing Portal FAQs
   * Coginiti Premium
     * Installing Coginiti PremiumPremium
     * Migrate from Coginiti Pro to Premium
     * User Management in Coginiti Premium
     * Coginiti Premium Logs
     * Upgrading Coginiti PremiumPremium
   * Release Notes
     * v22.5 Release Notes: Query Output Status, Notifications Filtering,
       BigQuery Partitioned Tables
     * v22.4 Release Notes: Version History Compare, Quick Stats for Query
       Results, CoginitiScript
     * v22.3 Release Notes: Aginity is now Coginiti Pro and Coginiti Premium
 * Database Explorer
   * Overview
     * Using the Database Explorer in Coginiti Pro
     * Connection Templates (Premium)Premium
     * Import and Export Connections
     * Authentication Types by platform supported in Coginiti Pro and Coginiti
       Premium
   * Configuring Connections in Coginiti Pro
     * Yellowbrick
     * Amazon Redshift
     * Snowflake
     * Netezza
     * Microsoft SQL Server
     * Postgres, Tanzu Greenplum, Amazon RDS, and Amazon Aurora
     * IBM Db2 Warehouse
     * Apache Hive
     * Generic JDBC (Oracle, MySQL, Teradata, etc.)
     * BigQuery
   * Configuring Connections in Coginiti Premium
     * Coginiti Premium Database Connections OverviewPremium
     * Downloading DriversPremium
     * Setting up Netezza ConnectionsPremium
 * Query & Results
   * Query Editor
     * Command Palette Tips and Tricks
     * Writing your First Query
     * Common Actions in the Query Panel
     * Query Autocomplete & Snippet Support
     * Multiple Cursors
     * Hover Over 'Select*' to See Table Details
     * Using Parameters in your Query
     * Working with Errors in the Query Panel
     * Execute Query to a File
   * Results Grid
     * Output Tab When Executing Queries
     * Creating Charts
     * Interacting with Query Results
     * Exporting Query Results to CSV or TSV
     * Exporting Data to Excel
     * Applying Sum and Other Aggregations to Query Results
     * Pivoting Query Results
     * Setting Row Limit for UsersPremium
 * CoginitiScript
   * Tutorials
     * Getting Started with CoginitiScript
     * Using Macros
     * Dynamically Generating SQL
   * Language Reference
     * What is CoginitiScript
     * Code Blocks
     * Packages
     * Metadata Properties
     * Publication
     * Expressions, Loops and Conditions
     * Constants
     * Macros
 * Catalog
   * Using Coginiti Catalog
     * Creating and Editing Assets within the Coginiti Query Catalog
     * Importing and Exporting Assets from Coginiti Catalog
     * Catalog Versioning
     * Sharing Catalog Asset Folders with OthersPremium
   * Scheduling in Coginiti Premium
     * How to Set up a Schedule?Premium
     * Saving Schedules (Premium)Premium
     * Reusing Schedules (Premium)Premium
     * Finding the Scheduled Items (Premium)Premium
 * Discovery & Notifications
   * Overview
     * Using Notifications Panel
     * Using Discovery Panel
 * Data Upload
   * Bulk Load
     * Bulk Loading Data to Redshift & Snowflake
     * Data Upload Templates
   * Data Insert
     * Data Insert
 * Guides
   * Knowledge Base
     * Connect to Redshift using Microsoft Azure Active Directory SSO with MFA
     * Log4j Remote Code Execution Vulnerability (CVE-2021-44228)
     * Managing Files in Coginiti
     * How to Setup SSH Tunnel with Coginiti Pro
     * Using Coginiti Catalog to Make Exporting to a File (via CoginitiScript)
       Even Easier
     * Using the Github Repository and Community Queries for Coginiti Pro and
       Premium
     * How to do a Fresh Install of Coginiti Pro
     * Connect Coginiti Pro™ or Coginiti Premium™ to Hive with Kerberos
       Authentication
   * Troubleshooting
     * Sending System Information to Support
     * Cannot Download Drivers via Connection Screen
     * Debugging JDBC Connectivity Issues with Cogniti Pro or Premium - Step 1


Toggle navigation


MACROS

Revised September 28, 2022 05:01

Macros are blocks which content will be inlined (substituted) into the caller
block. This mimic the current behavior of our catalog assets.

Macros are defined using an #+macro directive. Optionally, it could accept
arguments.

Macros are called in the same way as block.

In the following example we define countryGroup macro, which return a column
expression that we are using inside a SELECT statement to get a country group.

#+macro countryGroup(country)
#+meta {
  :doc "Given a name of the country column returns a CASE statement to get a country group."
}
#+begin
  CASE
    WHEN {{ country }} IN ('US', 'CA') THEN 'NA'
    WHEN {{ country }} IN ('GB', 'FR', 'DE', 'IT', 'PL', 'SE') THEN 'EU'
    WHEN {{ country }} IN ('AU') THEN {{ country }}
    ELSE 'Other'
  END
#+end

SELECT
  country AS country,
  {{ countryGroup(country="country") }} AS country_group,
  device_type AS device_type,
  sum(revenue) AS revenue,
  sum(pageviews) AS pageviews,
  sum(sessions) AS sessions
FROM
  {{ fact.sales() }}
GROUP BY
  country,
  country_group,
  device_type
;



Was this article helpful?

0 out of 0 found this helpful
Have more questions? Submit a request

TABLE OF CONTENTS

Macros
 * Macros


ARTICLES IN THIS SECTION

 * What is CoginitiScript
 * Code Blocks
 * Packages
 * Metadata Properties
 * Publication
 * Expressions, Loops and Conditions
 * Constants
 * Macros

Copyright © Coginiti Corporation