WiseOwl Training - Established 1992 Wise Owl Training

Established May 1992
30 years in business
Wise Owl Training
30 years in business
See 529 reviews for our classroom and online training
If you found this blog useful and youâ€™d like to say thanks you can click here to make a contribution. Thanks for looking at our blogs!

BLOGS BY TOPIC

BLOGS BY AUTHOR

BLOGS BY YEAR

How to write queries in DAX to interrogate SSAS tabular models
Part eight of an eight-part series of blogs

As well as creating measures to aggregate data in tabular models using DAX, you can also write queries to extract data - this blog shows you how!

This blog is part of our online SSAS Tabular tutorial; we also offer lots of other Analysis Services training resources.

Posted by Andy Brown on 12 February 2016

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

# Other useful DAX functions

To wrap up this section, I thought I'd show a couple of other potentially useful DAX functions.

## Using ROW to Display One Row of Data

It can be useful when testing DAX to be able to show single values, using the ROW function.  The syntax is:

ROW(

Name for the first column you want to display,
Calculation expression for this column,

...,

Name for the last column you want to display,
Calculation expression for this column

)

The ROW function is similar to a SELECT statement in SQL run without a FROM clause.

Here's an example query, listing out the current user name, time and number of products:

-- show the current user and time

EVALUATE

ROW (

"Current user",

USERNAME (),

"Current time",

FORMAT ( NOW (), "HH:mm:ss" ),

"Number of products",

COUNT ( Product[ProductId] )

)

This would give these results:

This query would display these 3 bits of information.

## Using CONTAINS to Check if a Field Value Exists

The CONTAINS function has the following syntax, and returns TRUE or FALSE

CONTAINS(

Name of table to search,

Name for the first column to look in,
Value to look for,

...,

Name of the last column to look in,
Value to look for

)

Here's an example of the function, showing whether there's a product called Wol with a list price of £3.95 (there is):

-- look for product with specific

-- name and price

EVALUATE

ROW (

"Does WOL exist?",

CONTAINS (

Product,

Product[ProductName],

"Wol",

Product[FullPrice],

3.95

)

)

Here are the unexciting results from running this query:

A product called WOL costing £3.95 does exist in the Product table.

And on that slightly anti-climactic note, I've finished showing the DAX query syntax that I wanted to cover!

This blog has 0 threads