MDX Calculated Member CrossJoin question - olap

I have an MDX query with the following calculated member:
with member [Measures].[BBOX] as
Count(
Filter(
CrossJoin([Dim Response].[Response ID].Children, [Dim Question].[Question Text].Children),
[Measures].[Question Bottom Box] > 0
)
)
The idea is that I want a count of the combinations of two members of a dimension. (Forgive me if my MDX vocabulary is a little off). It is also based on some criteria.
The rest of the query looks like this:
select
{({[Measures].[TBOX], [Measures].[BBOX]},
[Dim Product].[Category Name].&[Office])} on columns,
{[Dim Question].[Question Text].Members} on rows
from H1_FY10_Revised
where ({[Dim Question].[Category Name].&[Partner]},
{[Dim Subsidiary].[Subsidiary Alias Name].&[Germany]})
My question is: does the slicing of data that occurs in the main query (the where clause) translate to the calculated member? Is there any sort of implicit join between the data that comes back from the calculated member and the axises in the main query?
Or another way to phrase it: does the cross join in the calculated member execute in the context of the main query?

The evaluation of the CrossJoin does not depend on the context, but the Filter function does.
Calculated members are evaluated in the context of the query bu your calculated member may have a constant value because:
[Dim Response].[Response ID].Children is equivalent to [Dim Response].[Response ID].DefaultMember.Children (see MSDN).
[Dim Question].[Question Text].Children is equivalent to [Dim Question].[Question Text].DefaultMember.Children
So the result of the CrossJoin does not depend on the slicer. Only the value of [Measures].[Question Bottom Box] will depend on the slicer.

Related

Writing a SPARQL query that constructs new triples with result from COUNT in an aggregate

I'm working with the Snap SPARQL tool in Protege so to add data into the ontology I have to use CONSTRUCT because it doesn't support INSERT (the tool gives the option to assert the new triples constructed back into the ontology). I want to count values with a specific value and assert the count of those values back into the ontology. I created a little test ontology regarding students and grades to help me figure this out. I have the following query which works:
SELECT ?student (COUNT(?test) AS ?tcount)
WHERE {?student test:tookTest ?test.
?test test:hasGrade test:A.}
GROUP BY ?student
This gives me a table with each student in one column and their number of A grades in the next. What I want to do next is to use the ?tcount to assert the data back into the ontology. I've tried various things like replacing the SELECT with a CONSTRUCT or using an embedded query:
CONSTRUCT {?student test:hasACount ?tcount.}
WHERE {
SELECT ?student (COUNT(?test) AS ?tcount)
WHERE {?student test:tookTest ?test.
?test test:hasGrade test:A.}
GROUP BY ?student}
I think the problem with this is that ?tcount isn't in scope of the surrounding query. I've tried several different options like using BIND to BIND ?tcount or grouping by ?tcount rather than ?student but no luck.

Dax measure to find and show parent values and self (self displays as blank())

I have a table that has budget amounts at Level 2 and amounts at Level 1. I have a slicer. when I select a value in the slicer, I need my dax to find its parent and show these levels (and blank() at the Level1). It is not a defined hierarchy, but I could make it one.
I am trying to produce the two results in the snip below. One example with D selected in the slicer, the results to its right. Second example is C... I can got my select value measure to work, but need help with "Budget $" measure
I am trying to write a budget measure that produces the results above.
Thanks,
Mike
You need to specify that you want the values from the Budget rows. Something like this:
Budget $ =
CALCULATE ( SUM ( Data[Value] ), Data[Type] = "Budget" )
This should replace the current type context (D or C in your example) with Budget.

How do I query Table A, joining fields from B *and* fields from C only referenced in B?

I have this sqlite database:
And I need to get the set from AssignmentMetric for a certain Athlete_id AND for Assignments which include a skill with Value X.
I've looked all over JOIN, LEFT JOIN but cannot find any examples that seems to match exactly this. I can query to get Assignment metrics for a particular Athlete ID And Assignment ID, but I am trying to narrow the Assignments to ones that are for a specific skill "of X value". How do I "reach through" the Assignment table to grab the value from the Skill table?
You could do:
SELECT ...
FROM
AssignmentMetric
INNER JOIN Assignment
ON AssignmentMetric.Assignment_id =
Assignment.Assignment_id
INNER JOIN
Skill
ON Skill.Skill_id = Assignment.Skill_id
WHERE ...
In the WHERE you can refer to the colums of the tables using the tablename.columnname notation.

Express conditions on two consecutive variable length relationships?

How to express a conditions for two consecutive variable length relationships?
Consider this partial query
MATCH(t1:Type{myID: 1})-[r:relType]->(:Type)-[rels:relType*0..]-(t2:Type{myID:100})
WHERE r.attr1>10
Basically I am trying to saying that there could be one or more relations from t1 to t2. The first relation r should satisfy a given condition on its attribute.
If this is the only relation between the two nodes then it's ok.
It at least another relation exist I want to add another condition such as:
WHERE r.attr1>10 AND r_next.attr2> r_prev.attr2+r_prev.attr1
where r_next and r_prev are consecutive relations: ()-[r_prev]->()-[r_next]-(). Note that at the first step r_prev is the first relation r.
I know rels is a collection but I do not know how to express such a condition.
Consecutive comparison like this isn't easy at this time, and it can't currently be evaluated during expansion.
You can do some filtering on this after, but it will be ugly.
We'll make use of the APOC Procedures for apoc.coll.pairsMin(), which takes a collection and returns a list of adjacent pairs.
MATCH (t1:Type{myID: 1}), (t2:Type{myID:100})
MATCH (t1)-[r:relType]->(:Type)-[rels:relType*0..]-(t2)
WHERE r.attr1>10
WITH t1, t2, apoc.coll.pairsMin(rels) as pairs
WHERE all(pair in pairs WHERE pair[0].attr1 + pair[0].attr2 < pair[1].attr2)
RETURN t1, t2 //or whatever you want to return from this

Oracle PL/SQL ORA-00937 "not a single-group group function"

Im working with the oracle pdf's to learn pl/sql.
There is an exercise where i have to create a new table with data out
of two other tables already existing. I thought this would do the trick:
CREATE TABLE new_depts
AS SELECT d.department_id, d.department_name, sum(e.salary) dept_sal
FROM employees e, departments d
WHERE e.department_id = d.department_id;
But this raises the following error:
SQL-Fehler: ORA-00937: not a single-group group function
00937. 00000 - "not a single-group group function"
I cant find something usefull about this error. From what i know yet
about SQL my code should work fine!
Am i wrong?
Try adding group by clause :
CREATE TABLE new_depts
AS SELECT d.department_id, d.department_name, sum(e.salary) dept_sal
FROM employees e, departments d
WHERE e.department_id = d.department_id
group by d.department_id,d.department_name
Update 1
You need to use group by clause in your select query because you are using aggregate function: sum(e.salary). If you are using aggregate function then you need to have group by clause. Please see here for more information about group by clause.
The main concept to understanding why aggregate functions or columns that are specified in the GROUP BY clause cannot be mixed with other non aggregate expressions in the select list is the level of detail of the value they produce. The select list of the SELECT statement can include only expressions that produce values that are on the same level of detail as others in that select list.
Example 1: incorrect
SELECT avg(col1) --> level of detail of the value is aggregated
,col2 --> level of detail of the value is only for one row
FROM table_a;
Example 2: correct
SELECT avg(col1) --> level of detail of the value is aggregated
,col2 --> level of detail of the value is aggregated
FROM table_a
GROUP BY col2;
By including a column in the GROUP BY clause you aggregate the specified column and change its level of detail from single row to aggregate.

Resources