Set Dataset Metric in Global Variables

gblack686
gblack686 Partner, Registered Posts: 62 Partner

I want to calculate the last day of a column in a dataset and use it dynamically in my SQL recipe. I'm not using Python so I don't know how to set it as a variable. Is there a way to call the metric straight from the SQL recipe? Or send the metrics to global variables after the dataset build?

Answers

  • Liev
    Liev Dataiker Alumni Posts: 176 ✭✭✭✭✭✭✭✭
    edited July 17

    Hi @gblack686

    If you're using SQL for your recipe and the statement looks something like this:

    SELECT column_1
           , column_2
           , column_date 
    FROM table

    you can just modify this to be

    SELECT column_1
           , column_2
           , column_date
           , (SELECT MAX(column_date) FROM table) AS column_date_max
    FROM table

    This syntax can sometimes be inefficient if dealing with many such columns on large and non-indexed tables, but it's simple to follow without needing joins.

Setup Info
    Tags
      Help me…