Showing posts with label table. Show all posts
Showing posts with label table. Show all posts

Friday, March 30, 2012

Memory Allocation Failure When Deploying AS2005 Project

Hi,

I have an AS2005 project that I am trying to deploy. It contains one fact table with approx 20 million rows. I have never had any problems deploying the project unitl recently. What is happening is when between 3 - 5 million of the rows have been read it will fall over, giving the following error message:

"Memory error: Allocation failure : Not enough storage is available to process this command. . Errors in the OLAP storage engine:"

I have read about this occurring during the processing of a data mining model, and a hotfix exists to solve this. However, my project contains no data mining at all.

Can anyone shed any light on this?

Dave

Hard drive failure? Hard drive full/not enough storage space?

If you use incremental updating for your cube you will need additional storage space temporarely.

Regards

Thomas Ivarsson

|||

Hard drive is fine, and has around 200 Gb free. I think this is a memory problem with the server. The server has 3Gb, and has been able to process the cube fine for the last 2 months so I cannot understand it.

What do you mean by incremental processing? I have 3 partitions set up, each with around 7 million rows. I have set the options to 'Sequential processing', and 'Separate transactions'. Is there anything else I can do?

Dave

|||

Looks like your machine doesnt have enoght memory to execute a processing command. Analysis Server tries estimate the memory needed to complete processing command and that is the error message you are seeing.

Try process separately every dimension and partition. If you still see the error message during partition processing try to reduce size of the partition by partitioning your data some more.

Edward Melomed.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

Edward,

I could understand this being the case if the there had always been this problem. However, the fact table does not have any more rows now it is erroring than it did when it was processing fine. In addition, the error occurs when only a small proportion of the rows have been read, so I cannot see how the machine could have run out of memory in this early stage of processing.

David

|||

This is not a situation where machine runs out memory. Analysis Server wouldnt even start processing if you dont have enoght memory available to comlete the operation. So what is happening, it tries to estimate how much memory it needs to complete the processing, then it requests from OS what is the memory avaliable at the moment and compares the two. If there isn't enoguh, you will see the error.

Now, In your case I am not clear what had happen before.

The two things to check.

1. As I suggested in previous reply. Try and process less things in parralel, try to partition some more. Anything causing Analysis Server to lower the estimates.

2. See the memory situation on your machine at the time of processing. Is there someone is consuming the memory you need for processing?

HTH.

Edward Melomed.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

I would recommend to create a job that will do a full process of each dimension first and a full process of all the cubes at last. Sorry if you have already done this.

You can set up this by choosing to process each dimension in management studio and script that action.

I have seen that processing with the option to process all related objects do not always work a espected.

Have you any hints if you set up a trace in profiler?

Regards

Thomas Ivarsson

|||

Thanks for for advice guys. I did a couple of things you mentioned which I thought I had already tried, but the project processed ok.

Firstly I processed each dimension individually. Then I processed the cube (which I have split into 3 partitions). I changed the processing settings to 'Sequential Processing' and 'One transaction at a time'. It took about an hour and a half (it used to take one hour), but I can live with that.

I would like to write a script for this but am not sure what form it would take. Would it be in SQL, MDX or XMLA? Could you give me a brief outline of the syntax required, to say process a single dimension. This would give me an idea of what I am aiming for.

Many thanks,

Dave

|||

Can anybody help with this?

Dave

|||

Right click on a dimension in management studio and choose process. In the next dialogue you will have the option to script that command to a new query window or to memory. Then you can see the XMLA syntax for this.

Regards

Thomas Ivarsson

Memory Allocation Failure When Deploying AS2005 Project

Hi,

I have an AS2005 project that I am trying to deploy. It contains one fact table with approx 20 million rows. I have never had any problems deploying the project unitl recently. What is happening is when between 3 - 5 million of the rows have been read it will fall over, giving the following error message:

"Memory error: Allocation failure : Not enough storage is available to process this command. . Errors in the OLAP storage engine:"

I have read about this occurring during the processing of a data mining model, and a hotfix exists to solve this. However, my project contains no data mining at all.

Can anyone shed any light on this?

Dave

Hard drive failure? Hard drive full/not enough storage space?

If you use incremental updating for your cube you will need additional storage space temporarely.

Regards

Thomas Ivarsson

|||

Hard drive is fine, and has around 200 Gb free. I think this is a memory problem with the server. The server has 3Gb, and has been able to process the cube fine for the last 2 months so I cannot understand it.

What do you mean by incremental processing? I have 3 partitions set up, each with around 7 million rows. I have set the options to 'Sequential processing', and 'Separate transactions'. Is there anything else I can do?

Dave

|||

Looks like your machine doesnt have enoght memory to execute a processing command. Analysis Server tries estimate the memory needed to complete processing command and that is the error message you are seeing.

Try process separately every dimension and partition. If you still see the error message during partition processing try to reduce size of the partition by partitioning your data some more.

Edward Melomed.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

Edward,

I could understand this being the case if the there had always been this problem. However, the fact table does not have any more rows now it is erroring than it did when it was processing fine. In addition, the error occurs when only a small proportion of the rows have been read, so I cannot see how the machine could have run out of memory in this early stage of processing.

David

|||

This is not a situation where machine runs out memory. Analysis Server wouldnt even start processing if you dont have enoght memory available to comlete the operation. So what is happening, it tries to estimate how much memory it needs to complete the processing, then it requests from OS what is the memory avaliable at the moment and compares the two. If there isn't enoguh, you will see the error.

Now, In your case I am not clear what had happen before.

The two things to check.

1. As I suggested in previous reply. Try and process less things in parralel, try to partition some more. Anything causing Analysis Server to lower the estimates.

2. See the memory situation on your machine at the time of processing. Is there someone is consuming the memory you need for processing?

HTH.

Edward Melomed.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

I would recommend to create a job that will do a full process of each dimension first and a full process of all the cubes at last. Sorry if you have already done this.

You can set up this by choosing to process each dimension in management studio and script that action.

I have seen that processing with the option to process all related objects do not always work a espected.

Have you any hints if you set up a trace in profiler?

Regards

Thomas Ivarsson

|||

Thanks for for advice guys. I did a couple of things you mentioned which I thought I had already tried, but the project processed ok.

Firstly I processed each dimension individually. Then I processed the cube (which I have split into 3 partitions). I changed the processing settings to 'Sequential Processing' and 'One transaction at a time'. It took about an hour and a half (it used to take one hour), but I can live with that.

I would like to write a script for this but am not sure what form it would take. Would it be in SQL, MDX or XMLA? Could you give me a brief outline of the syntax required, to say process a single dimension. This would give me an idea of what I am aiming for.

Many thanks,

Dave

|||

Can anybody help with this?

Dave

|||

Right click on a dimension in management studio and choose process. In the next dialogue you will have the option to script that command to a new query window or to memory. Then you can see the XMLA syntax for this.

Regards

Thomas Ivarsson

sql

Monday, March 26, 2012

members not shown in pivot table

Hi Guys,

Some members of my dimension are not shown when use it in a pivot table. To prove this, I've browsed the dimension using the Business Intelligence. I search the member using the Find member. filtered the data that were not displayed and the result showed me that the member exists.

Is there a problem with the structure of my dimension or with my data? How can I resolve this issue?

Please enlighten me on this one.

thanks in advance...

It is hard to say what is going on without actually seeing the dimension design.

Try first experimenting with smaller size dimensions. Try substituting dimension table in DSV with named query limiting only to the members you suspect not seeing.

Hope that helps
Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights

Friday, March 23, 2012

median query without using function

I have a table (cars) with 3 fields:
VIN, Class, sell_price
101, sports, 10000
102, sports, 11000
103, luxury, 9000
104, sports, 11000
105, sports, 11000
106, luxury, 5000
107, sports, 11000
108, sports, 11000
109, luxury, 9000
i need to write a query that WITHOUT USING A FUNCTION will return the
median selling price for each class of car. result should look like:
Class, Med_Price
luxury, 9000
sports, 11000
thanks to all u SQLers
>From your sample data it looks like you want the most commonly
occurring price for each vehicle (I thought this was
called the "mode", not the "median").
CREATE TABLE Cars(VIN INT,Class VARCHAR(10),sell_price INT)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(101, 'sports', 10000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(102, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(103, 'luxury', 9000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(104, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(105, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(106, 'luxury', 5000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(107, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(108, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(109, 'luxury', 9000)
GO
CREATE VIEW CarNums
AS
SELECT Class,sell_price,COUNT(*) as Num
FROM Cars
GROUP BY Class,sell_price
GO
SELECT c1.Class,c1.sell_price AS Med_Price
FROM CarNums c1
INNER JOIN (
SELECT Class,MAX(Num)
FROM CarNums
GROUP BY Class) C2(Class,Num) ON C2.Class=C1.Class
AND C2.Num=C1.Num
|||My mistake, you can get the medians using this
CREATE VIEW CarRank
AS
SELECT c1.VIN,
c1.Class,
c1.sell_price,
(SELECT COUNT(*) FROM Cars c2
WHERE c2.Class=c1.Class
AND ((c2.sell_price<c1.sell_price)
OR (c2.sell_price=c1.sell_price AND c2.VIN<=c1.VIN))) as
Rank,
(SELECT COUNT(*) FROM Cars c2
WHERE c2.Class=c1.Class) as MaxRank
FROM Cars c1
GO
SELECT Class,AVG(sell_price) AS Med_Price
FROM CarRank
WHERE Rank IN ((MaxRank+1)/2,(MaxRank/2)+1)
GROUP BY Class
|||I have a whoel chapter on verious ways to do this in SQL FOR SMARTIES.
Here is one answer.
Median with Characteristic Function
Anatoly Abramovich, Yelena Alexandrova, and Eugene Birger presented a
series of articles in SQL Forum magazine on computing the median (SQL
Forum 1993, 1994). They define a characteristic function, which they
call delta, using the Sybase sign() function. The delta or
characteristic function accepts a Boolean expression as an argument and
returns a 1 if it is TRUE and a zero if it is FALSE or UNKNOWN.
In SQL-92 we have a CASE expression, which can be used to construct the
delta function. This is new to SQL-92, but you can find vendor
functions of the form IF...THEN...ELSE that behave like the condition
expression in Algol or like the question markPcolon operator in C.
The authors also distinguish between the statistical median, whose
value must be a member of the set, and the financial median, whose
value is the average of the middle two members of the set. A
statistical median exists when there is an odd number of items in the
set. If there is an even number of items, you must decide if you want
to use the highest value in the lower half (they call this the left
median) or the lowest value in the upper half (they call this the right
median).
The left statistical median of a unique column can be found with this
query:
SELECT P1.bin
FROM Parts AS P1, Parts AS P2
GROUP BY P1.bin
HAVING SUM(CASE WHEN (P2.bin <= P1.bin) THEN 1 ELSE 0 END)
= (COUNT(*) + 1) / 2;
Changing the direction of the theta test in the HAVING clause will
allow you to pick the right statistical median if a central element
does not exist in the set. You will also notice something else about
the median of a set of unique values: It is usually meaningless. What
does the median bin number mean, anyway? A good rule of thumb is that
if it does not make sense as an average, it does not make sense as a
median.
The statistical median of a column with duplicate values can be found
with a query based on the same ideas, but you have to adjust the HAVING
clause to allow for overlap; thus, the left statistical median is found
by
SELECT P1.weight
FROM Parts AS P1, Parts AS P2
GROUP BY P1.weight
HAVING SUM(CASE WHEN P2.weight <= P1.weight
THEN 1 ELSE 0 END)
>= ((COUNT(*) + 1) / 2)
AND SUM(CASE WHEN P2.weight >= P1.weight
THEN 1 ELSE 0 END)
>= (COUNT(*)/2 + 1);
Notice that here the left and right medians can be the same, so there
is no need to pick one over the other in many of the situations where
you have an even number of items. Switching the comparison operators in
the two CASE expressions will give you the right statistical median.
The author's query for the financial median depends on some Sybase
features that cannot be found in other products, so I would recommend
using a combination of the right and left statistical medians to return
a set of values about the center of the data, and then averaging them,
thus:
SELECT AVG(P1.weight)
FROM Parts AS P1, Parts AS P2
HAVING (SUM(CASE WHEN P2.weight <= P1.weight -- left median
THEN 1 ELSE 0 END)
>= ((COUNT(*) + 1) / 2)
AND SUM(CASE WHEN P2.weight >= P1.weight
THEN 1 ELSE 0 END)
>= (COUNT(*)/2 + 1))
OR (SUM(CASE WHEN P2.weight >= P1.weight -- right median
THEN 1 ELSE 0 END)
>= ((COUNT(*) + 1) / 2)
AND SUM(CASE WHEN P2.weight <= P1.weight
THEN 1 ELSE 0 END)
>= (COUNT(*)/2 + 1));
An optimizer may be able to reduce this expression internally, since
the expressions involved with COUNT(*) are constants. This entire query
could be put into a FROM clause and the average taken of the one or two
rows in the result to find the financial median. In SQL-89, you would
have to define this as a VIEW and then take the average.
If you have SQL-2005, you can try something like (untested):
SELECT AVG(x),
ROW_NUMBER () OVER (ORDER BY x ASC) AS hi,
ROW_NUMBER () OVER (ORDER BY x DESC) AS lo,
FROM Foobar
WHERE hi IN (lo, lo-1, lo+1);
|||i don't do homework for college students.

median query without using function

I have a table (cars) with 3 fields:
VIN, Class, sell_price
101, sports, 10000
102, sports, 11000
103, luxury, 9000
104, sports, 11000
105, sports, 11000
106, luxury, 5000
107, sports, 11000
108, sports, 11000
109, luxury, 9000
i need to write a query that WITHOUT USING A FUNCTION will return the
median selling price for each class of car. result should look like:
Class, Med_Price
luxury, 9000
sports, 11000
thanks to all u SQLers>From your sample data it looks like you want the most commonly
occurring price for each vehicle (I thought this was
called the "mode", not the "median").
CREATE TABLE Cars(VIN INT,Class VARCHAR(10),sell_price INT)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(101, 'sports', 10000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(102, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(103, 'luxury', 9000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(104, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(105, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(106, 'luxury', 5000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(107, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(108, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(109, 'luxury', 9000)
GO
CREATE VIEW CarNums
AS
SELECT Class,sell_price,COUNT(*) as Num
FROM Cars
GROUP BY Class,sell_price
GO
SELECT c1.Class,c1.sell_price AS Med_Price
FROM CarNums c1
INNER JOIN (
SELECT Class,MAX(Num)
FROM CarNums
GROUP BY Class) C2(Class,Num) ON C2.Class=C1.Class
AND C2.Num=C1.Num|||My mistake, you can get the medians using this
CREATE VIEW CarRank
AS
SELECT c1.VIN,
c1.Class,
c1.sell_price,
(SELECT COUNT(*) FROM Cars c2
WHERE c2.Class=c1.Class
AND ((c2.sell_price<c1.sell_price)
OR (c2.sell_price=c1.sell_price AND c2.VIN<=c1.VIN))) as
Rank,
(SELECT COUNT(*) FROM Cars c2
WHERE c2.Class=c1.Class) as MaxRank
FROM Cars c1
GO
SELECT Class,AVG(sell_price) AS Med_Price
FROM CarRank
WHERE Rank IN ((MaxRank+1)/2,(MaxRank/2)+1)
GROUP BY Class|||I have a whoel chapter on verious ways to do this in SQL FOR SMARTIES.
Here is one answer.
Median with Characteristic Function
Anatoly Abramovich, Yelena Alexandrova, and Eugene Birger presented a
series of articles in SQL Forum magazine on computing the median (SQL
Forum 1993, 1994). They define a characteristic function, which they
call delta, using the Sybase sign() function. The delta or
characteristic function accepts a Boolean expression as an argument and
returns a 1 if it is TRUE and a zero if it is FALSE or UNKNOWN.
In SQL-92 we have a CASE expression, which can be used to construct the
delta function. This is new to SQL-92, but you can find vendor
functions of the form IF...THEN...ELSE that behave like the condition
expression in Algol or like the question markPcolon operator in C.
The authors also distinguish between the statistical median, whose
value must be a member of the set, and the financial median, whose
value is the average of the middle two members of the set. A
statistical median exists when there is an odd number of items in the
set. If there is an even number of items, you must decide if you want
to use the highest value in the lower half (they call this the left
median) or the lowest value in the upper half (they call this the right
median).
The left statistical median of a unique column can be found with this
query:
SELECT P1.bin
FROM Parts AS P1, Parts AS P2
GROUP BY P1.bin
HAVING SUM(CASE WHEN (P2.bin <= P1.bin) THEN 1 ELSE 0 END)
= (COUNT(*) + 1) / 2;
Changing the direction of the theta test in the HAVING clause will
allow you to pick the right statistical median if a central element
does not exist in the set. You will also notice something else about
the median of a set of unique values: It is usually meaningless. What
does the median bin number mean, anyway? A good rule of thumb is that
if it does not make sense as an average, it does not make sense as a
median.
The statistical median of a column with duplicate values can be found
with a query based on the same ideas, but you have to adjust the HAVING
clause to allow for overlap; thus, the left statistical median is found
by
SELECT P1.weight
FROM Parts AS P1, Parts AS P2
GROUP BY P1.weight
HAVING SUM(CASE WHEN P2.weight <= P1.weight
THEN 1 ELSE 0 END)
>= ((COUNT(*) + 1) / 2)
AND SUM(CASE WHEN P2.weight >= P1.weight
THEN 1 ELSE 0 END)
>= (COUNT(*)/2 + 1);
Notice that here the left and right medians can be the same, so there
is no need to pick one over the other in many of the situations where
you have an even number of items. Switching the comparison operators in
the two CASE expressions will give you the right statistical median.
The author's query for the financial median depends on some Sybase
features that cannot be found in other products, so I would recommend
using a combination of the right and left statistical medians to return
a set of values about the center of the data, and then averaging them,
thus:
SELECT AVG(P1.weight)
FROM Parts AS P1, Parts AS P2
HAVING (SUM(CASE WHEN P2.weight <= P1.weight -- left median
THEN 1 ELSE 0 END)
>= ((COUNT(*) + 1) / 2)
AND SUM(CASE WHEN P2.weight >= P1.weight
THEN 1 ELSE 0 END)
>= (COUNT(*)/2 + 1))
OR (SUM(CASE WHEN P2.weight >= P1.weight -- right median
THEN 1 ELSE 0 END)
>= ((COUNT(*) + 1) / 2)
AND SUM(CASE WHEN P2.weight <= P1.weight
THEN 1 ELSE 0 END)
>= (COUNT(*)/2 + 1));
An optimizer may be able to reduce this expression internally, since
the expressions involved with COUNT(*) are constants. This entire query
could be put into a FROM clause and the average taken of the one or two
rows in the result to find the financial median. In SQL-89, you would
have to define this as a VIEW and then take the average.
If you have SQL-2005, you can try something like (untested):
SELECT AVG(x),
ROW_NUMBER () OVER (ORDER BY x ASC) AS hi,
ROW_NUMBER () OVER (ORDER BY x DESC) AS lo,
FROM Foobar
WHERE hi IN (lo, lo-1, lo+1);|||i don't do homework for college students.sql

median query without using function

I have a table (cars) with 3 fields:
VIN, Class, sell_price
101, sports, 10000
102, sports, 11000
103, luxury, 9000
104, sports, 11000
105, sports, 11000
106, luxury, 5000
107, sports, 11000
108, sports, 11000
109, luxury, 9000
i need to write a query that WITHOUT USING A FUNCTION will return the
median selling price for each class of car. result should look like:
Class, Med_Price
luxury, 9000
sports, 11000
thanks to all u SQLers>From your sample data it looks like you want the most commonly
occurring price for each vehicle (I thought this was
called the "mode", not the "median").
CREATE TABLE Cars(VIN INT,Class VARCHAR(10),sell_price INT)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(101, 'sports', 10000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(102, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(103, 'luxury', 9000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(104, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(105, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(106, 'luxury', 5000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(107, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(108, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(109, 'luxury', 9000)
GO
CREATE VIEW CarNums
AS
SELECT Class,sell_price,COUNT(*) as Num
FROM Cars
GROUP BY Class,sell_price
GO
SELECT c1.Class,c1.sell_price AS Med_Price
FROM CarNums c1
INNER JOIN (
SELECT Class,MAX(Num)
FROM CarNums
GROUP BY Class) C2(Class,Num) ON C2.Class=C1.Class
AND C2.Num=C1.Num|||My mistake, you can get the medians using this
CREATE VIEW CarRank
AS
SELECT c1.VIN,
c1.Class,
c1.sell_price,
(SELECT COUNT(*) FROM Cars c2
WHERE c2.Class=c1.Class
AND ((c2.sell_price<c1.sell_price)
OR (c2.sell_price=c1.sell_price AND c2.VIN<=c1.VIN))) as
Rank,
(SELECT COUNT(*) FROM Cars c2
WHERE c2.Class=c1.Class) as MaxRank
FROM Cars c1
GO
SELECT Class,AVG(sell_price) AS Med_Price
FROM CarRank
WHERE Rank IN ((MaxRank+1)/2,(MaxRank/2)+1)
GROUP BY Class|||I have a whoel chapter on verious ways to do this in SQL FOR SMARTIES.
Here is one answer.
Median with Characteristic Function
Anatoly Abramovich, Yelena Alexandrova, and Eugene Birger presented a
series of articles in SQL Forum magazine on computing the median (SQL
Forum 1993, 1994). They define a characteristic function, which they
call delta, using the Sybase sign() function. The delta or
characteristic function accepts a Boolean expression as an argument and
returns a 1 if it is TRUE and a zero if it is FALSE or UNKNOWN.
In SQL-92 we have a CASE expression, which can be used to construct the
delta function. This is new to SQL-92, but you can find vendor
functions of the form IF...THEN...ELSE that behave like the condition
expression in Algol or like the question markPcolon operator in C.
The authors also distinguish between the statistical median, whose
value must be a member of the set, and the financial median, whose
value is the average of the middle two members of the set. A
statistical median exists when there is an odd number of items in the
set. If there is an even number of items, you must decide if you want
to use the highest value in the lower half (they call this the left
median) or the lowest value in the upper half (they call this the right
median).
The left statistical median of a unique column can be found with this
query:
SELECT P1.bin
FROM Parts AS P1, Parts AS P2
GROUP BY P1.bin
HAVING SUM(CASE WHEN (P2.bin <= P1.bin) THEN 1 ELSE 0 END)
= (COUNT(*) + 1) / 2;
Changing the direction of the theta test in the HAVING clause will
allow you to pick the right statistical median if a central element
does not exist in the set. You will also notice something else about
the median of a set of unique values: It is usually meaningless. What
does the median bin number mean, anyway? A good rule of thumb is that
if it does not make sense as an average, it does not make sense as a
median.
The statistical median of a column with duplicate values can be found
with a query based on the same ideas, but you have to adjust the HAVING
clause to allow for overlap; thus, the left statistical median is found
by
SELECT P1.weight
FROM Parts AS P1, Parts AS P2
GROUP BY P1.weight
HAVING SUM(CASE WHEN P2.weight <= P1.weight
THEN 1 ELSE 0 END)
>= ((COUNT(*) + 1) / 2)
AND SUM(CASE WHEN P2.weight >= P1.weight
THEN 1 ELSE 0 END)
>= (COUNT(*)/2 + 1);
Notice that here the left and right medians can be the same, so there
is no need to pick one over the other in many of the situations where
you have an even number of items. Switching the comparison operators in
the two CASE expressions will give you the right statistical median.
The author's query for the financial median depends on some Sybase
features that cannot be found in other products, so I would recommend
using a combination of the right and left statistical medians to return
a set of values about the center of the data, and then averaging them,
thus:
SELECT AVG(P1.weight)
FROM Parts AS P1, Parts AS P2
HAVING (SUM(CASE WHEN P2.weight <= P1.weight -- left median
THEN 1 ELSE 0 END)
>= ((COUNT(*) + 1) / 2)
AND SUM(CASE WHEN P2.weight >= P1.weight
THEN 1 ELSE 0 END)
>= (COUNT(*)/2 + 1))
OR (SUM(CASE WHEN P2.weight >= P1.weight -- right median
THEN 1 ELSE 0 END)
>= ((COUNT(*) + 1) / 2)
AND SUM(CASE WHEN P2.weight <= P1.weight
THEN 1 ELSE 0 END)
>= (COUNT(*)/2 + 1));
An optimizer may be able to reduce this expression internally, since
the expressions involved with COUNT(*) are constants. This entire query
could be put into a FROM clause and the average taken of the one or two
rows in the result to find the financial median. In SQL-89, you would
have to define this as a VIEW and then take the average.
If you have SQL-2005, you can try something like (untested):
SELECT AVG(x),
ROW_NUMBER () OVER (ORDER BY x ASC) AS hi,
ROW_NUMBER () OVER (ORDER BY x DESC) AS lo,
FROM Foobar
WHERE hi IN (lo, lo-1, lo+1);|||i don't do homework for college students.

median query without using function

I have a table (cars) with 3 fields:

VIN, Class, sell_price
101, sports, 10000
102, sports, 11000
103, luxury, 9000
104, sports, 11000
105, sports, 11000
106, luxury, 5000
107, sports, 11000
108, sports, 11000
109, luxury, 9000

i need to write a query that WITHOUT USING A FUNCTION will return the
median selling price for each class of car. result should look like:

Class, Med_Price
luxury, 9000
sports, 11000

thanks to all u SQLers>From your sample data it looks like you want the most commonly
occurring price for each vehicle (I thought this was
called the "mode", not the "median").

CREATE TABLE Cars(VIN INT,Class VARCHAR(10),sell_price INT)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(101, 'sports', 10000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(102, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(103, 'luxury', 9000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(104, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(105, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(106, 'luxury', 5000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(107, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(108, 'sports', 11000)
INSERT INTO Cars(VIN,Class,sell_price) VALUES(109, 'luxury', 9000)
GO
CREATE VIEW CarNums
AS
SELECT Class,sell_price,COUNT(*) as Num
FROM Cars
GROUP BY Class,sell_price

GO

SELECT c1.Class,c1.sell_price AS Med_Price
FROM CarNums c1
INNER JOIN (
SELECT Class,MAX(Num)
FROM CarNums
GROUP BY Class) C2(Class,Num) ON C2.Class=C1.Class
AND C2.Num=C1.Num|||My mistake, you can get the medians using this

CREATE VIEW CarRank
AS
SELECT c1.VIN,
c1.Class,
c1.sell_price,
(SELECT COUNT(*) FROM Cars c2
WHERE c2.Class=c1.Class
AND ((c2.sell_price<c1.sell_price)
OR (c2.sell_price=c1.sell_price AND c2.VIN<=c1.VIN))) as
Rank,
(SELECT COUNT(*) FROM Cars c2
WHERE c2.Class=c1.Class) as MaxRank
FROM Cars c1

GO

SELECT Class,AVG(sell_price) AS Med_Price
FROM CarRank
WHERE Rank IN ((MaxRank+1)/2,(MaxRank/2)+1)
GROUP BY Class|||I have a whoel chapter on verious ways to do this in SQL FOR SMARTIES.
Here is one answer.

Median with Characteristic Function

Anatoly Abramovich, Yelena Alexandrova, and Eugene Birger presented a
series of articles in SQL Forum magazine on computing the median (SQL
Forum 1993, 1994). They define a characteristic function, which they
call delta, using the Sybase sign() function. The delta or
characteristic function accepts a Boolean expression as an argument and
returns a 1 if it is TRUE and a zero if it is FALSE or UNKNOWN.

In SQL-92 we have a CASE expression, which can be used to construct the
delta function. This is new to SQL-92, but you can find vendor
functions of the form IF...THEN...ELSE that behave like the condition
expression in Algol or like the question markPcolon operator in C.

The authors also distinguish between the statistical median, whose
value must be a member of the set, and the financial median, whose
value is the average of the middle two members of the set. A
statistical median exists when there is an odd number of items in the
set. If there is an even number of items, you must decide if you want
to use the highest value in the lower half (they call this the left
median) or the lowest value in the upper half (they call this the right
median).

The left statistical median of a unique column can be found with this
query:

SELECT P1.bin
FROM Parts AS P1, Parts AS P2
GROUP BY P1.bin
HAVING SUM(CASE WHEN (P2.bin <= P1.bin) THEN 1 ELSE 0 END)
= (COUNT(*) + 1) / 2;

Changing the direction of the theta test in the HAVING clause will
allow you to pick the right statistical median if a central element
does not exist in the set. You will also notice something else about
the median of a set of unique values: It is usually meaningless. What
does the median bin number mean, anyway? A good rule of thumb is that
if it does not make sense as an average, it does not make sense as a
median.

The statistical median of a column with duplicate values can be found
with a query based on the same ideas, but you have to adjust the HAVING
clause to allow for overlap; thus, the left statistical median is found
by

SELECT P1.weight
FROM Parts AS P1, Parts AS P2
GROUP BY P1.weight
HAVING SUM(CASE WHEN P2.weight <= P1.weight
THEN 1 ELSE 0 END)
>= ((COUNT(*) + 1) / 2)
AND SUM(CASE WHEN P2.weight >= P1.weight
THEN 1 ELSE 0 END)
>= (COUNT(*)/2 + 1);

Notice that here the left and right medians can be the same, so there
is no need to pick one over the other in many of the situations where
you have an even number of items. Switching the comparison operators in
the two CASE expressions will give you the right statistical median.

The author's query for the financial median depends on some Sybase
features that cannot be found in other products, so I would recommend
using a combination of the right and left statistical medians to return
a set of values about the center of the data, and then averaging them,
thus:

SELECT AVG(P1.weight)
FROM Parts AS P1, Parts AS P2
HAVING (SUM(CASE WHEN P2.weight <= P1.weight -- left median
THEN 1 ELSE 0 END)
>= ((COUNT(*) + 1) / 2)
AND SUM(CASE WHEN P2.weight >= P1.weight
THEN 1 ELSE 0 END)
>= (COUNT(*)/2 + 1))
OR (SUM(CASE WHEN P2.weight >= P1.weight -- right median
THEN 1 ELSE 0 END)
>= ((COUNT(*) + 1) / 2)
AND SUM(CASE WHEN P2.weight <= P1.weight
THEN 1 ELSE 0 END)
>= (COUNT(*)/2 + 1));

An optimizer may be able to reduce this expression internally, since
the expressions involved with COUNT(*) are constants. This entire query
could be put into a FROM clause and the average taken of the one or two
rows in the result to find the financial median. In SQL-89, you would
have to define this as a VIEW and then take the average.

If you have SQL-2005, you can try something like (untested):

SELECT AVG(x),
ROW_NUMBER () OVER (ORDER BY x ASC) AS hi,
ROW_NUMBER () OVER (ORDER BY x DESC) AS lo,
FROM Foobar
WHERE hi IN (lo, lo-1, lo+1);|||i don't do homework for college students.

Wednesday, March 21, 2012

Measures to columns in Excel

Dear anyone

I am transfering the information from the cube to Excel.

My wizard places all measures in the pivot table to one column. I am using Excel 2003.

I would like to place the measures to different columns to get a result which is easy to read and copy.

Could anyone advice me how this can be done ?

Thanks !

Matti

You just have to drag & drop the field "Data" from the rows to the columns.|||

Thanks Rmi

Your advice sounds simple, I expected the same.

The problem is that but my Add-button is inhibited when

trying to do that. Could this be caused by cube definitions ?

Matti

|||

If I try to use drag and drop, I get an error from Excel. Translation of error message is something like this: "The field You are transfering can't be placed in this area of the pivot table".

Matti

|||I don't think it comes from your cube. I am sorry if my answer seems a little too simple, but are you sure you drag & drop the field on the header of the columns (not the content of the table). In fact you can put numeric values in the content of table, but dimension attributes need to be in row headers or column headers or filter.|||

I want to summarize, that I can easily drag and drop all dimensions to either lines or to columns Measures I can only place to the same column.

Matti

|||Yes, of course, sorry I got lost... I just wanted you to drag and drop the field "data" which represents the Measures on the header of the column. And if it doesn't work, then I will let someone else help you because I don't have another idea...|||

Thanks for kind help Rèmi !

This is a question of the layout of the report and the form of the paper.

What I get is:

DimA1 DimA2

DimB1 MV1A1B1 MV1A2B1

MV2A1B1 MV2A2B1

DimB2 MV1A1B2 MV1A2B2

MV2A1B2 MV2A2B2

What I want to get:

DimA1 DimA2

DimB1 MV1A1B1 MV2A1B1 MV1A2B1 MV2A2B1

DimB2 MV1A1B2 MV2A1B2 MV1A2B2 MV2A2B2

.

.

.

Matti

Measures dependant on another measure.

I have a fact table that has sales data for products.

I have to fields in my fact table, WantDateId and InvoicedDateId which are integer representation of a date that join to the time dimension table.

I also have measures for feet, pounds, sales dollars, and material cost.

I have a bunch of dimensions for product type, sales rep, territory, shipped date…

I my cube I want to show a picture of sales for three things broken down over the dimensions.

What has been ordered

What has been invoiced

What is outstanding (backlog).

Most important is the current month where some will be shipped and some will be backlog.

The key here is that if the invoiceDateId = 0 then it has not shipped.

In order for aggregations to work, do I have to add columns to my fact table?This would mean I would need three of each measure.Is there a way to get this with calculated measures?

Hello. Here you have some links to design advices for your question.

http://www.kimballgroup.com/html/designtipsPDF/DesignTips2000%20/KimballDT2MultipleTime.pdf

http://www.kimballgroup.com/html/designtipsPDF/DesignTips2002/KimballDT37ModelingPipeline.pdf

http://www.kimballgroup.com/html/designtipsPDF/DesignTips2003/KimballDT42Combining.pdf

http://www.kimballgroup.com/html/articlesArchitecture/articlesAdvancedFact.html

I am not sure of what you would like to accomplish but sales data and snapshots, like OrderStock are normally not included in the same fact table.

HTH

Thomas Ivarsson

Measure Slicing Problem

Hi,

Please let me know whether the following requirement is possible in SQL Server Analysis Services 2005.

I have a fact table from which I have 4 measures M1, M2, M3 and M4. I have a dimension say D1,

Now I want that while browsing cube data the dimension D1 should slice M1 but it should not slice M2, M3 and M4.

What I feel is if we add the dimension to the fact table in Dimension Usage then it will slice all the measures coming from the fact table. If we remove the linkage of the dimension with the fact table in the Dimension Usage then the dimension will not slice any of the measures coming from that fact table.

The only solution that comes to my mind is by creating a duplicate of the fact table. But I dont want to do this as it would increase redundancy and make the DSV more complex.

Please let me know if I can do it in some other way.

Thanks in advance.

Regards,

Abhishek.

If M2-M4 are not related to D1 it sounds like they should be in a different fact table. However you should be able to achieve a similar outcome, buy overriding the context of D1 using a scope statement like the following.

SCOPE ({Measures.M2, Measures.M3, Measures.M4});

this = (D1.[All]);

END SCOPE;

Which pretty much says that for M2:M4, return the value of D1 at the top level, regardless of the current context of D1

|||

Hi,

Can you please tell me where should I write this scope statement.

Shoul I write it where I create the calculated member.

Thanks

Abhishek

|||You can only use scopes in the calculations section of the cube. You can either switch to script view and enter them or click the button on the tool bar that lets you add a new script command.|||

"The only solution that comes to my mind is by creating a duplicate of the fact table" - how about adding a Named Query on the fact table, which eliminates the field for D1 in the fact table? Then a new measure group could be created with this Named Query as the fact table, and measures M2, M3, M4. If the original fact table is like:

FT: <D1, D2, D3, D4, M1, M2, M3, M4>

then the Named Query could be like:

select D2, D3, D4, sum(M2) as M2, sum(M3) as M3, sum(M4) as M4

from FT

group by D2, D3, D4

Measure Slicing Problem

Hi,

Please let me know whether the following requirement is possible in SQL Server Analysis Services 2005.

I have a fact table from which I have 4 measures M1, M2, M3 and M4. I have a dimension say D1,

Now I want that while browsing cube data the dimension D1 should slice M1 but it should not slice M2, M3 and M4.

What I feel is if we add the dimension to the fact table in Dimension Usage then it will slice all the measures coming from the fact table. If we remove the linkage of the dimension with the fact table in the Dimension Usage then the dimension will not slice any of the measures coming from that fact table.

The only solution that comes to my mind is by creating a duplicate of the fact table. But I dont want to do this as it would increase redundancy and make the DSV more complex.

Please let me know if I can do it in some other way.

Thanks in advance.

Regards,

Abhishek.

If M2-M4 are not related to D1 it sounds like they should be in a different fact table. However you should be able to achieve a similar outcome, buy overriding the context of D1 using a scope statement like the following.

SCOPE ({Measures.M2, Measures.M3, Measures.M4});

this = (D1.[All]);

END SCOPE;

Which pretty much says that for M2:M4, return the value of D1 at the top level, regardless of the current context of D1

|||

Hi,

Can you please tell me where should I write this scope statement.

Shoul I write it where I create the calculated member.

Thanks

Abhishek

|||You can only use scopes in the calculations section of the cube. You can either switch to script view and enter them or click the button on the tool bar that lets you add a new script command.|||

"The only solution that comes to my mind is by creating a duplicate of the fact table" - how about adding a Named Query on the fact table, which eliminates the field for D1 in the fact table? Then a new measure group could be created with this Named Query as the fact table, and measures M2, M3, M4. If the original fact table is like:

FT: <D1, D2, D3, D4, M1, M2, M3, M4>

then the Named Query could be like:

select D2, D3, D4, sum(M2) as M2, sum(M3) as M3, sum(M4) as M4

from FT

group by D2, D3, D4

Measure Slicing Problem

Hi,

Please let me know whether the following requirement is possible in SQL Server Analysis Services 2005.

I have a fact table from which I have 4 measures M1, M2, M3 and M4. I have a dimension say D1,

Now I want that while browsing cube data the dimension D1 should slice M1 but it should not slice M2, M3 and M4.

What I feel is if we add the dimension to the fact table in Dimension Usage then it will slice all the measures coming from the fact table. If we remove the linkage of the dimension with the fact table in the Dimension Usage then the dimension will not slice any of the measures coming from that fact table.

The only solution that comes to my mind is by creating a duplicate of the fact table. But I dont want to do this as it would increase redundancy and make the DSV more complex.

Please let me know if I can do it in some other way.

Thanks in advance.

Regards,

Abhishek.

If M2-M4 are not related to D1 it sounds like they should be in a different fact table. However you should be able to achieve a similar outcome, buy overriding the context of D1 using a scope statement like the following.

SCOPE ({Measures.M2, Measures.M3, Measures.M4});

this = (D1.[All]);

END SCOPE;

Which pretty much says that for M2:M4, return the value of D1 at the top level, regardless of the current context of D1

|||

Hi,

Can you please tell me where should I write this scope statement.

Shoul I write it where I create the calculated member.

Thanks

Abhishek

|||You can only use scopes in the calculations section of the cube. You can either switch to script view and enter them or click the button on the tool bar that lets you add a new script command.|||

"The only solution that comes to my mind is by creating a duplicate of the fact table" - how about adding a Named Query on the fact table, which eliminates the field for D1 in the fact table? Then a new measure group could be created with this Named Query as the fact table, and measures M2, M3, M4. If the original fact table is like:

FT: <D1, D2, D3, D4, M1, M2, M3, M4>

then the Named Query could be like:

select D2, D3, D4, sum(M2) as M2, sum(M3) as M3, sum(M4) as M4

from FT

group by D2, D3, D4

Monday, March 19, 2012

Measure expressions and currency conversion

OK - here is my scenario... I have a fact table containing one measure: Sales. The values of the measure are stored in the same currency (DKK) for all records. In another fact table I have exchange rates for four different currencies per day for a 15 year period (approx. 22000 records). I have built a cube around these fact tables containing two measure groups.

Measure Group 1
Measure: Sales
Dimensions: Time, Product, Company

Measure Group 2
Measure: Exchange rate
Dimensions: Time, Currency

The only shared dimension between the two measure group is thus Time... The currency dimension contains one attribute hierarchy (CurrencyCode) with IsAggregatable set to False and DefaultMember set to DKK.

For the measure Sales, I have created a measure expression like this:

[Measures].[Sales] / [Measures].[Currency]

I thought this should work - i.e. give me the opportunity to select any of the four available currencies and have the value of Sales displayed accordingly. However - it does not. Sad Instead my Sales measures is multiplied by 4, which corresponds to the number of currencies for which I have exchange rates in my exchange rate fact table. Why is this? Am I not modelling the scenario correctly?

I hope someone can help, since this really puzzles me! Idea

Hi Michael,

I think I might know what's going on here: you need to give your Currency dimension a many-to-many relationship with Measure Group 1 using Measure Group 2 as the intermediate measure group. Does this work?

Regards,

Chris|||Hi Chris,

Sound very reasonable... I will give it a try. Do you think this approach will perform better than an MDX script like this (inspired by one of your own blog entries: http://spaces.msn.com/members/cwebbbi/Blog/cns!1pi7ETChsJ1un_2s41jm9Iyg!299.entry)

([Measures].[Sales],LEAVES([Time]),LEAVES([Currency])) = [Measures].[Sales] / [Measures].[Exchange Rate]

?

Chris, thanks for your input. It would be a shame to say that Microsoft has spent too much time documenting how to use measure expressions. Smile|||Well, I think it might perform a little bit better, but to be honest I'm not sure. You'll have to try both!|||Michael,

Since you've marked my first reply as solving your problem, I don't suppose you can tell us what the performance on your cube is like now? Do your currency conversion queries run fast enough with measure expressions? I'd really be interested to know.

Chris|||Hi Chris

Unfortunately, I have not yet had the time to implement the solution with measure expressions yet (currently, we are using the MDX Script approach for solving the problem). I will, however, test it with measure expressions as well and report back my findings. I am sure that the solution you pointed out is correct wrt. using measure expressions (also after having reviewed the implementation in the AdventureWorks cube), which is why I marked your answer as correct. Smile

I really appreciate your input!|||

Mosha's latest blog entry is also highly relevant to this problem:
http://sqljunkies.com/WebLog/mosha/archive/2005/12/06/multiplication_perf.aspx

|||OMG... Smile Really a very nice article. It guess it also means that if we have to divide two measures with each other in a measure expression like this: A / B, and B has the higher granularity, then it would be a good idea to invert the B measure (1/B) and instead make a measure expression like this: B * A...

Lesson learned... I guess. Big Smile

Still has not tested the measure expression vs. the MDX Script approach, though...|||Hi,

I finally got around to test this... My results show that measure expressions performs marginally better compared to using MDX scripts. But the two approaches perform almost just as well (and they do perform remarkably good) - a statement Mosha has previously made as well. So which approach do I prefer? Well - since using measure expressions has the best peformance (not by much, though), I will be using these. Perhaps there are scenarios where you cannot model your UDM to fit this approach, and MDX scripts might be more appropriate then...

I hope that these findings are useful to others...|||Well... What do you know?! Big Smile I just found a scenario myself in which using measure expressions for currency conversion is not possible. One of my measures used "LastNonEmpty" as the aggregation function and measure expressions do not support this... Will of course be using the MDX script approach for solving this... Idea

Measure expressions and currency conversion

OK - here is my scenario... I have a fact table containing one measure: Sales. The values of the measure are stored in the same currency (DKK) for all records. In another fact table I have exchange rates for four different currencies per day for a 15 year period (approx. 22000 records). I have built a cube around these fact tables containing two measure groups.

Measure Group 1
Measure: Sales
Dimensions: Time, Product, Company

Measure Group 2
Measure: Exchange rate
Dimensions: Time, Currency

The only shared dimension between the two measure group is thus Time... The currency dimension contains one attribute hierarchy (CurrencyCode) with IsAggregatable set to False and DefaultMember set to DKK.

For the measure Sales, I have created a measure expression like this:

[Measures].[Sales] / [Measures].[Currency]

I thought this should work - i.e. give me the opportunity to select any of the four available currencies and have the value of Sales displayed accordingly. However - it does not. Sad Instead my Sales measures is multiplied by 4, which corresponds to the number of currencies for which I have exchange rates in my exchange rate fact table. Why is this? Am I not modelling the scenario correctly?

I hope someone can help, since this really puzzles me! Idea

Hi Michael,

I think I might know what's going on here: you need to give your Currency dimension a many-to-many relationship with Measure Group 1 using Measure Group 2 as the intermediate measure group. Does this work?

Regards,

Chris|||Hi Chris,

Sound very reasonable... I will give it a try. Do you think this approach will perform better than an MDX script like this (inspired by one of your own blog entries: http://spaces.msn.com/members/cwebbbi/Blog/cns!1pi7ETChsJ1un_2s41jm9Iyg!299.entry)

([Measures].[Sales],LEAVES([Time]),LEAVES([Currency])) = [Measures].[Sales] / [Measures].[Exchange Rate]

?

Chris, thanks for your input. It would be a shame to say that Microsoft has spent too much time documenting how to use measure expressions. Smile|||Well, I think it might perform a little bit better, but to be honest I'm not sure. You'll have to try both!|||Michael,

Since you've marked my first reply as solving your problem, I don't suppose you can tell us what the performance on your cube is like now? Do your currency conversion queries run fast enough with measure expressions? I'd really be interested to know.

Chris|||Hi Chris

Unfortunately, I have not yet had the time to implement the solution with measure expressions yet (currently, we are using the MDX Script approach for solving the problem). I will, however, test it with measure expressions as well and report back my findings. I am sure that the solution you pointed out is correct wrt. using measure expressions (also after having reviewed the implementation in the AdventureWorks cube), which is why I marked your answer as correct. Smile

I really appreciate your input!|||

Mosha's latest blog entry is also highly relevant to this problem:
http://sqljunkies.com/WebLog/mosha/archive/2005/12/06/multiplication_perf.aspx

|||OMG... Smile Really a very nice article. It guess it also means that if we have to divide two measures with each other in a measure expression like this: A / B, and B has the higher granularity, then it would be a good idea to invert the B measure (1/B) and instead make a measure expression like this: B * A...

Lesson learned... I guess. Big Smile

Still has not tested the measure expression vs. the MDX Script approach, though...|||Hi,

I finally got around to test this... My results show that measure expressions performs marginally better compared to using MDX scripts. But the two approaches perform almost just as well (and they do perform remarkably good) - a statement Mosha has previously made as well. So which approach do I prefer? Well - since using measure expressions has the best peformance (not by much, though), I will be using these. Perhaps there are scenarios where you cannot model your UDM to fit this approach, and MDX scripts might be more appropriate then...

I hope that these findings are useful to others...|||Well... What do you know?! Big Smile I just found a scenario myself in which using measure expressions for currency conversion is not possible. One of my measures used "LastNonEmpty" as the aggregation function and measure expressions do not support this... Will of course be using the MDX script approach for solving this... Idea

measure counting distinct values from a field

How do I count the amount of distinct values from a column in a fact table as a calculated measure

Assume the primary key of my fact table is a composite of three columns (a,b,c).

How can I code a calculated measure to count every distinct value of column a, not the amount of rows in my fact table.

Any advise help would be appreciated!

All you need to do is change the measure type from Count to Distinct Count ... make sure you select Column A as your key column....

Measure change updates in Fact tables

Is there an industry standard method to populate Fact table columns with the
amount of change of a measure from one row to the next?
I have a FactSubscriptions (1 row = 1 week), and I wold like to have a
column of the price change from the previous week.
I'm wrestling with using tsql to join the Fact to itself offset by one week.
Progress is slowly being made, but I'm saying to myself "There's gotta be an
easier way!"
I at least need some keywords to do further research.
thanks,
Conrad
This type of query is usually done in the OLAP structures using MDX. Doing
it in t-sql would result in a poor performance.
If you do need to do it in t-sql please post sample of data and structures.
For example, how is date stored in your tables? As a datetime or you have a
week number or something?
MC
"Conrad" <Conrad@.discussions.microsoft.com> wrote in message
news:45C056A5-A015-4517-9CD8-F9D46D868968@.microsoft.com...
> Is there an industry standard method to populate Fact table columns with
> the
> amount of change of a measure from one row to the next?
> I have a FactSubscriptions (1 row = 1 week), and I wold like to have a
> column of the price change from the previous week.
> I'm wrestling with using tsql to join the Fact to itself offset by one
> week.
> Progress is slowly being made, but I'm saying to myself "There's gotta be
> an
> easier way!"
> I at least need some keywords to do further research.
> thanks,
> Conrad
>
|||1. Could you give me some OLAP/MDX keywords I could research further?
2. I have both WeekID and a date, but the "offset join" is done by WeekID.
I don't know OLAP or MDX yet, so I'll need to do this project in tsql. The
data is small, so
performance is not a problem.
Here's a representation of the data and tsql:
Table A
ID WeekID CustID Price PriceChange
1 1 90 100 0
2 2 90 110 10
3 3 90 110 0
4 4 90 110 0
5 1 91 100 0
6 2 91 100 0
7 3 91 120 20
8 4 91 120 0
Insert Table A Into ##TempB [sic]
Select ID, WeekID, CustID
From A
Inner Join ##TempB
On A.WeekID = ##TempB + 1
And A.CustID = ##TempB.CustID
tia,
Conrad
"MC" wrote:

> This type of query is usually done in the OLAP structures using MDX. Doing
> it in t-sql would result in a poor performance.
> If you do need to do it in t-sql please post sample of data and structures.
> For example, how is date stored in your tables? As a datetime or you have a
> week number or something?
>
> MC
>
> "Conrad" <Conrad@.discussions.microsoft.com> wrote in message
> news:45C056A5-A015-4517-9CD8-F9D46D868968@.microsoft.com...
>
>
|||You obviously need price change over the weeks for each custID (customer?).
Does this wokr for you?
select
A.price,
isnull((select A2.price from tableA A2 where A2.weekID = A.WeekID - 1
and A2.CustID = A.CustID), A.price) as PreviousPrice,
A.WeekID,
A.CustID
from
tableA A
Alternatively, you can use join as you did but using the same table.
select
A.price,
isnull(A2.Price,A.Price) as PreviousPrice,
A.WeekID,
A.CustID
from
tableA A
left join TableA A2 on A.WeekID = A2.WeekID - 1 ANDA.CustID = A2.CustID
MC
"Conrad" <Conrad@.discussions.microsoft.com> wrote in message
news:0E83399D-4B5C-40CE-988F-D58F9898F9E5@.microsoft.com...[vbcol=seagreen]
> 1. Could you give me some OLAP/MDX keywords I could research further?
> 2. I have both WeekID and a date, but the "offset join" is done by WeekID.
> I don't know OLAP or MDX yet, so I'll need to do this project in tsql. The
> data is small, so
> performance is not a problem.
> Here's a representation of the data and tsql:
> Table A
> ID WeekID CustID Price PriceChange
> 1 1 90 100 0
> 2 2 90 110 10
> 3 3 90 110 0
> 4 4 90 110 0
> 5 1 91 100 0
> 6 2 91 100 0
> 7 3 91 120 20
> 8 4 91 120 0
> Insert Table A Into ##TempB [sic]
> Select ID, WeekID, CustID
> From A
> Inner Join ##TempB
> On A.WeekID = ##TempB + 1
> And A.CustID = ##TempB.CustID
>
> tia,
> Conrad
>
> "MC" wrote:

Measure change updates in Fact tables

Is there an industry standard method to populate Fact table columns with the
amount of change of a measure from one row to the next?
I have a FactSubscriptions (1 row = 1 week), and I wold like to have a
column of the price change from the previous week.
I'm wrestling with using tsql to join the Fact to itself offset by one week.
Progress is slowly being made, but I'm saying to myself "There's gotta be an
easier way!"
I at least need some keywords to do further research.
thanks,
ConradThis type of query is usually done in the OLAP structures using MDX. Doing
it in t-sql would result in a poor performance.
If you do need to do it in t-sql please post sample of data and structures.
For example, how is date stored in your tables? As a datetime or you have a
week number or something?
MC
"Conrad" <Conrad@.discussions.microsoft.com> wrote in message
news:45C056A5-A015-4517-9CD8-F9D46D868968@.microsoft.com...
> Is there an industry standard method to populate Fact table columns with
> the
> amount of change of a measure from one row to the next?
> I have a FactSubscriptions (1 row = 1 week), and I wold like to have a
> column of the price change from the previous week.
> I'm wrestling with using tsql to join the Fact to itself offset by one
> week.
> Progress is slowly being made, but I'm saying to myself "There's gotta be
> an
> easier way!"
> I at least need some keywords to do further research.
> thanks,
> Conrad
>|||1. Could you give me some OLAP/MDX keywords I could research further?
2. I have both WeekID and a date, but the "offset join" is done by WeekID.
I don't know OLAP or MDX yet, so I'll need to do this project in tsql. The
data is small, so
performance is not a problem.
Here's a representation of the data and tsql:
Table A
ID WeekID CustID Price PriceChange
1 1 90 100 0
2 2 90 110 10
3 3 90 110 0
4 4 90 110 0
5 1 91 100 0
6 2 91 100 0
7 3 91 120 20
8 4 91 120 0
Insert Table A Into ##TempB [sic]
Select ID, WeekID, CustID
From A
Inner Join ##TempB
On A.WeekID = ##TempB + 1
And A.CustID = ##TempB.CustID
tia,
Conrad
"MC" wrote:

> This type of query is usually done in the OLAP structures using MDX. Doing
> it in t-sql would result in a poor performance.
> If you do need to do it in t-sql please post sample of data and structures
.
> For example, how is date stored in your tables? As a datetime or you have
a
> week number or something?
>
> MC
>
> "Conrad" <Conrad@.discussions.microsoft.com> wrote in message
> news:45C056A5-A015-4517-9CD8-F9D46D868968@.microsoft.com...
>
>|||You obviously need price change over the weeks for each custID (customer?).
Does this wokr for you?
select
A.price,
isnull((select A2.price from tableA A2 where A2.weekID = A.WeekID - 1
and A2.CustID = A.CustID), A.price) as PreviousPrice,
A.WeekID,
A.CustID
from
tableA A
Alternatively, you can use join as you did but using the same table.
select
A.price,
isnull(A2.Price,A.Price) as PreviousPrice,
A.WeekID,
A.CustID
from
tableA A
left join TableA A2 on A.WeekID = A2.WeekID - 1 ANDA.CustID = A2.CustID
MC
"Conrad" <Conrad@.discussions.microsoft.com> wrote in message
news:0E83399D-4B5C-40CE-988F-D58F9898F9E5@.microsoft.com...[vbcol=seagreen]
> 1. Could you give me some OLAP/MDX keywords I could research further?
> 2. I have both WeekID and a date, but the "offset join" is done by WeekID.
> I don't know OLAP or MDX yet, so I'll need to do this project in tsql. The
> data is small, so
> performance is not a problem.
> Here's a representation of the data and tsql:
> Table A
> ID WeekID CustID Price PriceChange
> 1 1 90 100 0
> 2 2 90 110 10
> 3 3 90 110 0
> 4 4 90 110 0
> 5 1 91 100 0
> 6 2 91 100 0
> 7 3 91 120 20
> 8 4 91 120 0
> Insert Table A Into ##TempB [sic]
> Select ID, WeekID, CustID
> From A
> Inner Join ##TempB
> On A.WeekID = ##TempB + 1
> And A.CustID = ##TempB.CustID
>
> tia,
> Conrad
>
> "MC" wrote:
>

meassure groups with different amount of dimensions

Hi everybody,

I've got a Fact Data table with a value and 16 dimensions.

Now I want to create a second measure group Color with a value and 3 dimensions.

I've filled this table with values and id's for each dimension.

Bu when I make an mdx query with a measure from the FactData and a measure from the second measure group (Color), only the first measure has a value, the second (the measure from Color) is null.

Is these something I've forgotton to set in the cube?

thanks in advance

Filip

Hi,

If you run a simple query (below) do you get two columns of data in the results?

select {[Measures].[Measure Group 1],[Measures].[Measure Group Color]} on 0

from [Cube]

results:

Measure Group 1 Measure Group Color

123231 123213

If not I suspect something else is wrong, perhaps check that you have set up the joins between the dimensions and the facts correctly. If you do get values in both, perhaps it is worth while posting your query.

Hope it helps,
Matt

|||

Hi,

that query runs.

but I have another problem now, this measure group I've created for storing color information, only can't have a Sum or Count as aggregation.

I cannot see the 65280 or ... value for the color I want to use.

I didn't included a period dimension to this measure group.

Is that the cause?

Filip

|||

Hi,

Sorry for delay I was investigating. If the measure is not aggregatable then you will get Null in the measure unless you go down to the granularity in which the data is held at. This is an area not that familar with and finding it difficult to prove.

But if you don't include a dimension in measure and the measures are aggregatable it will not causes nulls to appear, you get funny results. e.g.

select {[Measures].[Measure Group 1],[Measures].[Measure group 2]} on 0,

[Dimension only on measure group 1] on 1

from [cube]

Results:

Measure Group 1 Measure Group 2

dim a 45 1234 1234 being the total in measure group 2

dim b 23 1234

dim c 78 1234

Sorry I could answer it more positively.

Matt

|||

thank you for your help!

it works at a certain level.

at the granularity level, it works fine,

but once it starts aggregating, the value 256 becomes a sum of x times 256.

I have to solve that problem...

thansk for you help

Filip

MDX-Drillthrough

Hi,
I am trying to display the results of for example:
DRILLTHROUGH SELECT FROM [Request] WHERE [Day].[Day_Id].[5501]
inside a table of a report. I tried to follow
http://www.databasejournal.com/features/mssql/article.php/10894_3557476_10
but I didn't succeed:
I created a new dataset and entered the above statement into the Design mode
of the query builder. When I execute the statement, an error shows up:
"Query preparation failed. Additional information: Failed to parse the
query to detect if it is MDX or DMX. (MDXQueryGenerator)."
(In the Management Studio the query doesn't fail and shows the expected
results.)
What am I doing wrong?Use OLEDB instead of "Microsoft Analysis Services" as Datasource-Typ and it
works!
"Ralph Watermann" <We.Want@.NoSpam.de> schrieb im Newsbeitrag
news:eRMfBtQ8FHA.1276@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I am trying to display the results of for example:
> DRILLTHROUGH SELECT FROM [Request] WHERE [Day].[Day_Id].[5501]
> inside a table of a report. I tried to follow
> http://www.databasejournal.com/features/mssql/article.php/10894_3557476_10
> but I didn't succeed:
> I created a new dataset and entered the above statement into the Design
> mode of the query builder. When I execute the statement, an error shows
> up:
> "Query preparation failed. Additional information: Failed to parse the
> query to detect if it is MDX or DMX. (MDXQueryGenerator)."
> (In the Management Studio the query doesn't fail and shows the expected
> results.)
> What am I doing wrong?
>

MDX:time between fatcs / time spent in a state

Hi all

I am an MDX newbie and it happens i have to do immediately with a query that seems (to me) pretty unorthodox.

The fact table i have is made up of the following entities: StateMachineId, StateId, TransitionDateTime.
In fact, i have several State Machines that can find themselves in different states and i log in a DB the time of their transitions and the new state.
I need to generate reports mostly based on the time spent in each state and i have no clue on what is the best way to do that in mdx.
In sql, what i did was to join this FactTable (FT1) with itself (FT2) ON StateMachineId adding the condition that FT2.TransitionDateTime BETWEEN FT1.TransitionDateTime AND FT1.TransitionDateTime + SomeTimeInterval , in this way i narroewed the size of the join. At this point, i took the row from FT2 with the lesser TransitionDateTime .
All this works perfectly, but it is akward and pretty slow. Another downside is that some longer transitions (those longer than SomeTimeInterval) are excluded.
I think working with MDX could be better but, as i stated before, i am new in this field.
Do you have some ideas to create a suitable cube for these queries?

Thank You So Much

Best regards

Wentu
It's me again

I found this SQL solution:

Code Snippet

with modnums as (
select *, row_number() over (order by StateMachineId, TransitionDateTime) as rn
from FactTable
)
select m_this.StateMachineId, m_this.TransitionDateTime, m_next.StateId, m_next.TransitionDateTime, m_this.StateId, datediff(ms,m_this.TransitionDateTime, m_next.TransitionDateTime) elapsedTime
from
modnums m_this
inner join
modnums m_next
on m_next.rn = m_this.rn + 1
and m_this.StateMachineId = m_next.StateMachineId


It's working very well (Thankx to Rob Farley for this) .
Now, i would like to use it in Analysis Services but the "OVER" is not allowed in Named Queries. Any Idea on how to write this query in MDX ?

Thankx again

Wentu