Measures constrained by WHERE clause

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!

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

Similar Messages

  • Using a Dimension/ Measure in a Where clause of Another Dimension/ Measure in IDT

    Hi All
    I am building a Universe using Information Design Tool. In the Business Layer, I need to use a created Business Layer Dimension (not Tables) in a Where clause of another dimension as follow:
    Dimension: "Current Week No"
         SELECT
              budgets.dbo.Calenderweeks.WeekNo
         WHERE
              budgets.dbo.Calenderweeks.EndDate = convert(SMALLDATETIME, fn CURDATE()})  
    Dimension: "Last Week No"
         SELECT
              budgets.dbo.Calenderweeks.WeekNo
         WHERE
              budget.dbo.Calenderweeks  .WeekNo = @Select(Dimension\Current Week No) - 1
    The first dimension is working well. However, the "Last Week No" shows NOTHING (I do not get any value)
    Anyone can explain why I am not get any value from the second dimension, and how I can use a Dimension/ Measure in a Where clause of another Dimension/ Measure ?
    Thanks

    Short answer:
    Beware of object WHERE clauses. They are rarely (I'd almost say never) the solution to the problem you're trying to solve.
    Long answer:
    It doesn't work because you are inadvertently filtering the same value twice in two incompatible ways in the same SQL statement.  Both objects SELECT the same column in the database.  The first object uses a WHERE clause to set it to the current week.  The second object attempts to use a WHERE clause to set it to the previous week, but does so by selecting the first object, so you end up with both objects in your data provider.
    Remember that BO is going to place all the objects in your data provider in the same SQL (except of course where your context definition has ensured otherwise.), so you have two WHERE clauses in your generated SQL which attempt to find a line equal both the current week and the previous week... and returns, naturally, no results.
    Rewrite it with a derived table (as explained in the response above) and you'll get what you want.

  • Webi formula: Create sum with where clause on measure

    Hi,
    I am trying to create a sum of all values in a table which are greater than a specific threshold. Maybe someone can help me here. I haven't figured whether and how this is possible.
    Here is a simple example:
    Dimension
    Measure
    A
    12
    B
    8
    C
    25
    D
    3
    E
    11
    I would like to sum up all values that are greater than 10. So I would have 12 + 25 + 11 = 48.
    The formula I tried in WebI was:
    =Sum([Measure]) Where ([Measure] >= 10)
    The formula is validated with no errors, but the result gives me the grand total ignoring the where clause.
    In this example, that would be 12 + 8 + 25 + 3 + 11 = 59.
    Any idea, how to achieve a formula like the above?
    Thanks and regards,
    Stefan

    Hi Stefan,
    Write a formula
    =Sum([Measure]) Where ([Measure] >= 10 in ([Dimension ]))
    Ex:
    Below report have currency and their amount
    wrote a formula
    =Sum([Current Amount Bal]) Where ([Current Amount Bal] > 10,000 In ([Currency]))
    Regards,
    Mahi

  • How to change recordset bahaviour to accept dynamic column names in the where clause

    Hi
    im using php-mysql and i make a recordset and i want to make the column names in the where clause to be dynamic like
    "select id,name from mytable where $tablename-$myvar";
    but when i do this my i break the recordset and it disappear
    and when i use variables from advanced recordset it only dynamic for the value of the column not for the column name
    and when i write the column name to dynamic as above by hand it truns a red exclamation mark on the server behaviour panel
    so i think the only way is to change the recordset behaviour is it? if so How to make it accept dynamic column names?
    thanks in advance.

    As bregent has already explained to you, customizing the recordset code will result in Dreamweaver no longer recognizing the server behavior. This isn't a problem, but it does mean that you need to lay out your dynamic text with the Bindings panel before making any changes. Once you have changed the recordset code, the Bindings panel will no longer recognize the recordset fields.
    Using a variable to choose a column name is quite simple, but you need to take some security measures to ensure that the value passed through the query string isn't attempting SQL injection. An effective way of doing this is to create an array of acceptable column names, and check that the value matches.
    // create array of acceptable values
    $valid = array('column_name1', 'column_name2', 'column_name3');
    // if the query string contains an acceptable column name, use it
    if (isset($_GET['colname']) && in_array($_GET['colname'], $valid)) {
      $col = $GET['colname'];
    } else {
      // set a default value if the submitted one was invalid
      $col = 'column_name1'
    You can then use $col directly in the SQL query.

  • Bad performance when calling a function in where clause

    Hi All,
    I have a performance problem when executing a query that contains a function call in my where clause.
    I have a query with some joins and a where clause with some regular filters. But one of these filters is a function, and its input parameters are columns of the tables used in the query.
    When I run it with only a few rows in the tables, it goes ok. But as the number of rows grows, performance falls geometrically, even when my where clause filters the result to only a few rows.
    If I take the function call off of the where clause, then run the query and then call the function for each returned row, performance is ok. Even when the number of returned rows is big.
    But I need the function call to be in the where clause, because I can't build a procedure to execute it.
    Does anyone have any clue on how to improve performance?
    Thanks,
    Rafael

    You have given very little information...
    >
    If I take the function call off of the where clause, then run the query and then call the function for each returned row, performance is ok. Even when the number of returned rows is big. Can you describe how you measured the performance for a big result set without the function? For example lets say there had been 10.000 rows returned (which is not really big, but it is astarting point). Did you see all 10.000 rows? A typical mistake is to execute the query in some tool like Oracle SQL Developer or TOAD and measure how fast the first couple of rows are returned. Not the performance of the full select.
    As you can see from this little detail there are many questions that you need to address first before we can drill down to the root of your problem. Best way is to go through the thread that Centinul linked and provide all that information first. During the cause of that you might discover that you learn things on the way that help a lot for later tuning problems/approaches.
    Edited by: Sven W. on Aug 17, 2009 5:16 PM

  • Does derived table use where clause fillters inside

    dear all.
    Table "A" has two cols aid and col1 , aid is pk.
    Table "B" has two cols  bid , aid , and colb .
    followin query can be formulated in other ways ,but i wanted to ask something about query processing.
    select aid,aa.ca,aa.cb
    from A
    left join
    (select aid, b.colb ca ,b1.colb  cb
     from A
    left join B on a.aid=b.aid and b.colb='r'
    left join B b1 on a.aid=b1.aid and b1.colb='e'
    ) aa
    where a.aid (1,2)
    i wanted to know if i put the where clause "where a.aid(1,2) in side derived table aa
    then will it change its plan in any case or it is sufficant to put where clasue in last
    or i should put the where clause in side the derive table "aa" also.
    yours sincerley

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior ON SQL forums. Is your boss this rude to you?? 
    CREATE TABLE Alphas
    (alpha_id INTEGER NOT NULL PRIMARY KEY,
     col1 INTEGER NOT NULL);
    Thanks to your rude, poor narrative I have to guess about the second table: 
    CREATE TABLE Betas
    (beta_id INTEGER NOT NULL PRIMARY KEY, 
     alpha_id INTEGER NOT NULL
       REFERENCES Alphas(alpha_id), 
     colb CHAR(1) NOT NULL);
    Your query is awful. OUTER JOINs are rare in a properly designed schemA. The DRI should guarantee inner joins!  We seldom need to re-name columns. 
    >> I wanted to know if I put the where clause WHERE A.alpha_id(1,2) in side derived table aa <<
    That is not a syntactically invalid search condition; did you mean 
    “WHERE A.alpha_id IN (1,2)” ??
    Why did you de-normalize your results? My guess is that you can get the same data with this: 
    SELECT alpha_id, colb
      FROM Betas AS B
     WHERE colb IN ('r', 'e')
       AND alpha_id IN (1, 2);
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • "create columns with a where clause" in BMM

    Hi All,
    I have a question about OBI EE Meta data layer.
    We have OBIEE sitting on a Data Warehouse with a star schema.
    Our Fact table holds the following fields...
    EmployeeID
    CompanyID
    Measure ID
    Measure Name
    MEASURE
    This is what we have in the physical layer, BMM layer and the presentation layer but I want to be able to "create columns with a where clause"
    So my fact table in the presentation layer would look like this
    Amount Sold
    Unit Cost
    Company Amount
    I thought I could just create a logical column with
    Amount Sold = Measure
    where Measure Name = "Amount Sold"
    But I can't seem to find any to do that.
    Any ideas?
    Thanks

    Or you simply map your measure in the Logical Table source as something like :
    CASE WHEN MEASURE_NAME = 'Amount Sold' THEN MEASURE ELSE 0 END.
    You need to decide if you want the where clause adding in the Logical table source (be careful you will need a seperate LTS for each measure, this will mean more than one SQL being fired when you have more than one measure in the report).
    Or you go with this case method on each measure, be able to have all the measures mapped in 1 LTS, include all those in the report and they will be retrieved by one SQL block.

  • Using hierarchy attribute in where clause! ERROR

    Hi,
    I'm currently working on a report where I'm using a where clause in my MDX querry on the "ID" hierarchy, but also would like to show the ID in the report (table/matrix) in the ON COLUMNS part.
    As I read it is not possible to use a slicer in an axis hierarchy, so I used a workaround by putting the lower granularity (attribute) in the where clause. This workaround works in my MDX query BUT does not work when I convert the querry for
    my reporting! I get the same error again
    ON COLUMNS, NON EMPTY
           Filter(
                 NonEmpty(
                        [Wager].[Wager number].[Wager
    number],
                        [Measures].[Payment amount]
                 * [Date].[Date].[Date]
                 [Measures].[Payment amount] > Cdbl(@PAR_Payment_Amount)
           * [Point of sale].[POS default connection].[POS default connection]
    WHERE
    [Point of sale].[Regional office].&[22]
    * {[Date].[Calendar - Bonus Program].[Invoice week].&[2014]&[06],[Date].[Calendar - Bonus Program].[Invoice          week].&[2014]&[07]}
           * {[Point of sale].&[10005397],[Point of sale].&[10005397]}
    --> In my report MDQ query designer 
    WHERE
           {StrToMember(@PAR_Regional_Office)}
           * StrToSet(@PAR_Year_Week)
           * {StrToSet(@PAR_ClientID)}
    Any suggestions?

    Still looking for help if possible:)

  • Time's error with a metric for DashBoard in the WHERE Clause - @Prompt

    Hello,
    I have a problem with a measure in Universe. In the WHERE clause I have the typical @Prompt to interact with DashBoard:
    "Fact.Time_Key between @Prompt('BEGIN_DATE','D',,mono,free) And @Prompt('END_DATE','D',,mono,free)" *
    *Fact.Time_Key is a Date Field
    I check many options to solve the problem, which is: "The conversion of char data type to smalldatetime data type result in an out-of-range smalldatetime value." For example I saw many forums, I check the regional settings with IT and I also change the prm file that my universe's connection use but it still doesn't work.
    So I believe that the date format of my field (Fact.Time_Key) is different to @Prompt date format
    Any Suggestion?
    Regards
    Romá

    Hi Roman,
    I am not sure but I thought there was also a 'BEGIN_DATETIME' option
    Regards
    Alan

  • Date Range in Where clause

    I have ssas DB with two cubes, they share the date dimension. My query shows users on the dimension and visit as a measure. In the where clause I have range of dates. I have this strange behavior that after a FULL cube process I don't see
    any data when applying the range. I'm sure that I have data for the range because when I filter each day desperately I can see data. Another weird scenario is that if the date is on the dimension I can see data. The thing that solve it is when process DATA
    the cubes. This my query:
    select non empty [Users].[User].[User] columns,
    {[Measures].[Visits]} on rows
    from [System Visit] where
    ([Dim_Date].[Georgian Calendar].[Date ID].&[20150125]:[Dim_Date].[Georgian Calendar].[Date ID].&[20150202])
    Any thoughts what can be the issue? Thanks

    Hi liranbn,
    According to your description, you want to return the Visits within a date range. Right?
    In this scenario, please modify your MDX query like below:
    select nonempty([Users].[User].[User].members,[Measures].[Visits]) on columns,
    [Measures].[Visits] on rows
    from [System Visit]
    where
    ({[Dim_Date].[Georgian Calendar].[Date ID].&[20150125]:[Dim_Date].[Georgian Calendar].[Date ID].&[20150202]})
    Please see MDX with AdventureWorks sample:
    If you have any question, please feel free to ask.
    Simon Hou
    TechNet Community Support

  • Which line in where clause gets executed first

    Hi everyone!
    I have some sqls which look like this
    select ...
    from table A, table B
    where a.name = b.name
    and a.name in (....)Now, which one of this is executed first? the where clause or the and clause?
    Joining the tables is preferably done in where clause?
    I am using Oracle 10g.
    Please give me some guidance.
    Thank You.
    Nith

    user645399 wrote:
    When I deal with very large tables I notice that it takes too long, so was wondering if I move the table join to the and clause, it can join and then apply the filter which could be faster instead of filtering and joining the table.Define "+too long+" - what metric and baseline are used?
    You need to have some kind of baseline of what acceptable performance is and then some metric to measure against the baseline to determine whether the process has acceptable performance or not.
    What I mean by this is that "+too long+" is an arbitrary statement that cannot be evaluated. It the workload is huge, that workload will take some time too process. If a workload is tiny, that will take less time to process.
    But "+too long+" gives no indication what the workload is. And "+large table+" is meaningless as a SQL against a billion row table can be minimal workload (e.g. unique index read), whereas a SQL against a small table can be a huge workload (e.g. cartesian join and full table scan).
    You first need to determine WHAT the workload is, before judging it as "+too slow+".
    I have no idea on how is the execution plan.And one of the first steps is looking at the execution plan. SQL code is source code (like C/C++ or Visual Basic source code). This cannot be executed - it needs to be parsed and compiled into an executable program.
    For C/C++ and Visual Basic, that is typically an +.exe+ or +.ddl+ executable. SQL source code is compiled into an executable program called a cursor. The execution plan of that cursor shows the structure of this program and what this program will (technically) do step-by-step.
    From the execution plan you can make calls such as, are the available indexes used optimally, did the CBO (the creator of the execution) made sane decisions based on the available data and stats it has for the tables and database?
    The execution plan can also highlight errors in the source code - for example, table foo is scanned twice using a full table scan. This does not make sense to hit the same data set twice in a single SQL - so why is the SQL source code written that way?
    The bottom line is that you need to know WHAT it is doing to determine if the performance is acceptable or not. If not, then you need to determine WHY it is doing what it is doing and whether there are better alternatives.

  • Is this conditional WHERE clause possible?

    Let's say at the beginning of a stored procedure I do this:  DECLARE @hasActualHours BIT
    I'll then employ logic to set this local variable to either 0 or 1.
    I'm interested to know if I can then use it to either include or exclude entire "AND..." clauses within my WHERE clause?
    For example:
    SELECT ...
    FROM ...
    WHERE
      Clause 1... AND
      Clause 2... AND
    Now, I have a Clause 3 but I
    only want to include it if @hasActualHours = 1.
    Is it possible to do something like that in T-SQL?
    Robert

    >> Let's say at the beginning of a stored procedure I do this:  DECLARE @hasActualHours BIT
    I'll then employ logic to set this local variable to either 0 or 1.
    I'm interested to know if I can then use it to either include or exclude entire "AND..." clauses within my WHERE clause? <<
    No, no, no, no!  Your whole approach is totally wrong. Not a little wrong, but totally wrong. You just heard that from someone who helped write the SQL Standards, has 1200+ articles and 10 books on this topic. Please listen. 
    SQL is a declarative language, not a procedural flow control language. Declarative languages have no flow to control; there is no IF-THEN-ELSE, no loops. 
    SELECT ...
      FROM … 
     WHERE Clause 1... 
       AND Clause 2... 
       AND <expression for actual hour count> > 0.00;
    >> Is it possible to do something like that in T-SQL? <<
    Sure, we can kludge it! But first post a statement for your boss to see that you do not care about maintaining code, performance and professionalism. This would be bad for your career; like saying you eat babies on a parenting forum :) That is what the other
    replies are! 
    right now, you are the kid on a baseball diamond asking by which end do you hold the umpire. You are not thinking in SQL yet. My rule of thumb is you need a full year of SQL with a good mentor (read that last phrase again). It is a different mindset. 
    I wrote a book, THINKING IN SETS, to help with the change. See if that helps. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • @prompt not functioning in where clause

    I have attempted to use the following in a where clause of a dimension object:
    ORGANIZATION_DIM.ORGANIZATION_ID = @Prompt('Which Organization?','A','Cash Receipts\Organization ID',mono,constrained,not_persistent,{'ORG0001'})
    When I use the object in a WebI query, the following SQL is generated:
    SELECT
      ORGANIZATION_DIM.ORGANIZATION_ID
    FROM
      ORGANIZATION_DIM
    WHERE
    ( ( ORGANIZATION_DIM.ORGANIZATION_ID = @Prompt('Which Organization?','A','Cash Receipts\Organization ID',mono,constrained,not_persistent,{'ORG0001'}) )  )
    When I run the query, the "query in process" pop up appears briefly and then nothing but a windows hourglass.
    If I use the same @prompt in the where clause of a filter object and use the filter object in my WebI query, the same SQL is generated.  When I run the query using the filter, the prompt appears as expected and the query runs successfully.
    Any thoughts on what may be happening here?

    Hi
    two more question:
    1) Does 'Cash Receipts\Organization ID' appear before or after the dimension object you are talking about in the object browser in your universe?
    2) Can you consider installing the latest Fix PAck (1.9)?
    Regards,
    Stratos

  • Is `WHERE` clause pointless inside a sub-select?

    WHERE is part of the definition of a sub-select:
    [WITH [<calc-clause> ...]]
    SELECT [<axis-spec> [, <axis-spec> ...]]
    FROM [<identifier> | (< sub-select-statement >)]
    [WHERE <slicer>]
    [[CELL] PROPERTIES <cellprop> [, <cellprop> ...]]
    < sub-select-statement > :=
    SELECT [<axis-spec> [, <axis-spec> ...]]
    FROM [<identifier> | (< sub-select-statement >)]
    [WHERE <slicer>]I understand that a subselect does not reduce dimensionality or set context.
    If overall context of a script is not driven via a sub-select then is there ever a point in using this WHERE clause in the subselect? 
    An example in Adventure Works:
    SELECT
    [Measures].[Order Count] ON 0
    [Geography].[Country] * [Product].[Category] ON 1
    FROM
    SELECT
    [Geography].[Country].[Australia] ON 0
    FROM [Adventure Works]
    WHERE
    [Product].[Category].[Bikes]

    Hi WhyTheQ,
    According to your description, you want to know if the Where clause is working when the main select statement is not driven via the sub-select. Right?
    In MDX, Where clause is used for defining slicer axis so that only the data intersecting the with the specified member will be returned. It will work in the sub-select to restrict the data. However, the return result from sub-select should match
    the set on your axis. In this scenario, your sub-select returns an aggregation value of a dimension member, but in your main select row level expects a tuple set. So your can't get the result and it will throw error.
    Reference:
    Specifying the Contents of a Slicer Axis (MDX)
    Best Regards,
    Simon Hou
    TechNet Community Support

  • The query does not reference any table when attempting to build the WHERE clause.  (IES 00022)

    Hi
    I am getting below error.
    The query does not reference any table when attempting to build the WHERE clause.  (IES 00022)
    This error is in Validating Measue object in IDT.
    It is not throwing error for dimensions objects but only for measure objects.
    My BO version is 4.1
    Backend is Teradata 14.1.
    Regards
    Gaurav.

    Hi
    In the dimension/Measure definition, you can select the table. Find the below screenshot.
    If you still getting the issue…Can you please share your screenshot, for better understanding the issue?

Maybe you are looking for

  • Vendor Master Update

    Hi, My requirement is to interface with leagacy system the vendor master data . For this i am using RFBIKR00 in my z-prg. The structures that are getting passed are BGR00, BLF00, BLFA1, BLFB1... In structure BLF00 I am getting the T-code & the Vendor

  • Contact picture cannot be seen while talking on the iPhone

    This query is with regards to the contact picture, which cannot be seen while I am talking on the iPhone. If you see the review of iphone on the website (apple.com)..u will see a small picture next to John Appleseed. However in my iphone i cannot see

  • Freight Setup in SAP 2007B

    Dear all,    I was using SAP 2007A  where there is a  treeview node named 'Freight'  under Administration->Setup->General.    I did not see the same option in SAP 2007B. Is there any setup/setting that needs to be done to enable this option in the tr

  • Mail not showing in inbox.

    Hi, I am trying to send a mail to SBWP. what is happening is i am able to see the mail in outbox but not in inbox. let me know what do i do?

  • Has anyone had an email saying Adobe can't bill using current payment information.

    Has anyone had an email from Adobe saying they cannot bill using current payment information on the account? I haven't made any changes and they have been happily taking the monthly subscription for many months. There are no issues with my payment in