Measures constrained by WHERE clause

Advertisement
Post Author: GregPye
CA Forum: Semantic Layer and Data Connectivity
Hi
We have a fact table, containing Animal Count, and a dimension table joining onto the fact table, that gives us the species.
We want to create separate measures in the universe, such that we get SpeciesA Count, SpeciesB Count, SpeciesC Count etc etc as measure objects in our universe.
To do this we have constrained our measure by adding a WHERE clause, i.e. : Species_Dim.SpeciesName = 'SpeciesA'
This causes an issue, because we end up getting SQL like this:
SELECT
Animal_Fact.Animal_Count,
Animal_Fact.Animal_Count,
Animal_Fact.Animal_Count
FROM
Animal_Fact, Species_Dim
WHERE
Species_Dim.Species_Name = 'SpeciesA'
AND Species_Dim.Species_Name = 'SpeciesB'
AND Species_Dim.Species_Name = 'SpeciesC'
etc etc etc
Obviously this runs SQL that will never return any results, because of these AND statements in the Where...
Any ideas?
Because the measure objects are all in the same table, the "Multiple SQL statements for each measure" is NOT a solution option here...
I'd really rather not have to alias for each species, which I think is the solution, but thought I would put this problem out there to see if there are any better resolutions that my current one!!!!
Many thanks!
Advertisement

Replay

Greg,
The 1st problem that I see is that you are using two tables w/o joining them.
there are two ways to join them:
1) in the WHERE clause:
FROM
Animal_Fact, Species_Dim
WHERE
Animal_Fact.AnimalID = Species_Dim.AnimalID AND (what ever additional criteria you need)
2) actually using an explicit join (the preferred method):
FROM
Animal_Fact
INNER JOIN Species_Dim
ON Animal_Fact.AnimalID = Species_Dim.AnimalID
WHERE
(what ever additional criteria you need)
In addition to the INNER JOIN, you have LEFT OUTER JOIN, RIGHT OUTER JOIN and FULL OUTER JOIN.
-The RIGHT and FULL aren't used too often...
The 2nd problem I see... the reason that you aren't getting any results is this:
WHERE
Species_Dim.Species_Name = 'SpeciesA'
AND Species_Dim.Species_Name = 'SpeciesB'
AND Species_Dim.Species_Name = 'SpeciesC'
You're saying that "Species_Dim.Species_Name"; has to 3 different things... It can't, so you get no results.
Hope this helps,
Jason