560 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
How to write queries in DAX to interrogate SSAS tabular models Part seven 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. |
You can combine results from two tables using GENERATE, GENERATEALL or CROSSJOIN.
GENERATE corresponds to a SQL inner join; GENERATEALL to a SQL outer join.
The GENERATEALL function allows you to show for every row in one table the related rows in another:
-- show for each species
-- its list of animals
EVALUATE
GENERATEALL (
Species,
RELATEDTABLE(Animal)
)
This would show for each species the animals it contains:
The four species, with the animals each contains.
Typically, you use GENERATE or GENERATEALL to show only certain matching rows for each main table row. For example, the following query lists out each row from the species table, together with the two-legged animals for each species:
-- show every species, and the two-legged
-- animals corresponding to it
EVALUATE
GENERATEALL (
Species,
CALCULATETABLE ( Animal, Animal[Legs] = 2 )
)
This would give the following results. Because we've used GENERATEALL, we also get the species which have no two-legged animals (mammals, reptiles and amphibians):
The results of running the query.
You could run the query above using GENERATE instead of GENERATEALL, like this:
-- show only those species with two-legged
-- animals corresponding
EVALUATE
GENERATE (
Species,
CALCULATETABLE ( Animal, Animal[Legs] = 2 )
)
This would then give the following results:
The GENERATE function corresponds to an inner join in SQL, so we only see species which have two-legged animals.
The CROSSJOIN function mimics the SQL CROSS JOIN statement, and is (in my humble opinion) about as useful. Here's an example:
-- show every species, and every two-legged
-- animal
EVALUATE
CROSSJOIN(
Species,
CALCULATETABLE ( Animal, Animal[Legs] = 2 )
)
What this variant on our query would show is every species, and for each species every two-legged animal:
Struggling to see why this would be useful? Me, too.
As I delve further into exotic DAX commands, I'll finish this blog by showing the ROW and CONTAINS functions.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2023. All Rights Reserved.