What's new ⬇ Download Reportworq
⬇ Guide PDF

Data model variables#

A variable lets a report supply a value to a data model view at run time: the fiscal year of a P&L, the region of a burst, the cost center of a budget submission. You write it as a {{Token}}, for example {{Year}}, and set how it behaves on the view's Variables tab. The values flow downstream to Preview, to reports, to bursting, and to the Excel add-in.

Where variables come from#

A view's Variables tab lists every variable the view uses, in up to three groups:

Group Where the token is Required?
Connection - required In the view's query: its SQL, MDX, or DAX, or a connector's query setting, for example WHERE fiscal_year = {{Year}}. Always. A query cannot run with a hole in it.
Filters In a field filter's value on the Fields tab, for example the Region field filtered to {{Region}}. Your choice. An optional filter variable left blank drops its filter, so the view returns every region.
From the joined views In the input views of a joined view. See Variables of a joined view.

The sample value is not a default#

A view whose query has a {{Token}} needs a value to run while you build it, so the Design or Connection tab shows a Connection values sidebar for a sample value. Reportworq uses the sample to run the query, work out the view's fields, and fill in Preview while you author.

The sample is only for authoring. It never becomes the variable's default, and reports never see it. Set the default on the Variables tab. Preview starts from the default, and from the sample value when a view has no default. A joined view never asks for a sample value: see Variables of a joined view.

Set a default and whether a value is required#

  1. Open the data model, select the view in the rail, and select the Variables tab.
  2. In the box on the variable's row, enter its default: the value Preview and reports use when nothing overrides it, for example 2024. For an optional filter variable the box reads Optional: leave blank to skip the filter.
  3. For a filter variable, select or clear Required. A connection variable always shows Required and cannot be made optional.
  4. Select Save Changes.

A report, a burst, or the Excel add-in can override the default with its own value. In Preview, a required variable left blank brings a warning, "No value for required variable(s)", that names it.

Variables in Preview#

The Variable values pane in Preview starts with each variable's default. For a joined view that is the same value a run would use. Two rules then apply:

A box you have not touched follows the view's defaults as you change them.

Set how a report prompts for a variable#

Select Prompt on a variable's row to open its prompt settings. They decide what the person running the report sees when asked for the value.

Select Save Changes when you are done.

How a value is filled into a query#

People type values into prompts and Excel cells feed values into variables, so Reportworq makes each value safe where it is pasted into a SQL, MDX, or DAX query. A value can never change what the query does: it can only be a value. Reportworq looks at where each {{Token}} sits in the query text and fills it accordingly.

The rules by position are the following.

Where the token sits What happens to the value
Inside a quoted string, such as '{{Market}}' The quote character is doubled, so O'Brien becomes the text O'Brien, not the end of the string.
Inside a quoted name, such as [{{Column}}], "{{Column}}", or a DAX '{{Table}}' The closing character is doubled in the same way.
Bare, not inside quotes Only a number is accepted.
Inside a comment A value that would end the comment, or start a new one, is refused.

Two kinds of bare value are accepted as well as a number:

A value that breaks a rule fails the run with a message that names the variable, for example: The value for "Region" can't be used: it is pasted into the query without quotes, so it only takes a number (or, inside IN ( ), a list such as 1, 2, 3 or 'East', 'West').

Write tokens so they fill cleanly#

The following patterns cover most queries.

To pass Write Example value
A text value in SQL WHERE market = '{{Market}}' Pacific Northwest
A number in SQL WHERE fiscal_year = {{Year}} 2024
A date in SQL WHERE posted_on >= '{{From}}' 2024-01-01
Several values in SQL WHERE region IN ({{Regions}}) 'East', 'West'
A member in MDX [Region].[{{Region}}] East
Members in MDX { {{Regions}} } [Region].[East], [Region].[West]
Text in DAX "{{Region}}" East

Database rules#

How a database reads quotes and comments differs, so Reportworq applies the rules of the view's connection:

Planning Analytics, Analysis Services, and Power BI#

MDX and DAX follow the same idea:

Field filters#

A value that reaches a field filter, and is pushed down to the source as part of its query, is written by its field's type: a number is checked and written as a number; text, dates, and true/false values are quoted with their quotes doubled; and each item of a list is written the same way. Nothing in the filter needs quoting by hand.

Use a value as query text#

Sometimes a variable is meant to change the query itself: a column to sort by (ORDER BY {{SortColumn}}), a table or schema name (FROM {{Schema}}.ledger), or an MDX set expression. A value like that is not a number, so it is refused unless you opt in.

  1. On the view's Variables tab, select Prompt on the variable's row.
  2. Under In the query, select Raw query text, pasted as is.
  3. Select Save Changes.

The value is then pasted into the query exactly as given, with no checking. The setting is stored on the view's own query, so only the data model's author can turn it on: nothing a report or a caller sends can set it.

Warning: A raw query text variable can change what the query does. Whoever can supply its value can rewrite that part of the query against the source, with the connection's permissions. Turn it on only for a variable that genuinely holds query text, and give it a list of Choices with Also allow typing a value that isn't on the list turned off, so people pick from known values.

If you are upgrading#

Earlier releases pasted a value into the query as raw text. Queries that relied on that can stop working after the upgrade. Check views that match any of these patterns:

The run's error names the variable and the reason, so the failing view is easy to find.

Feedback on this page

Comments, questions, requests, or something missing or unclear? Email us - the page you are on is filled in for you.

Email feedback on this page

Or write to support@reportworq.com directly.