Tuesday, March 20, 2012
Background Colour of Matrix cells
I have a matrix that goes no bigger than 4 colums and 4 rows big.
I need to have different colours for certain cells within the matrix.
e.g for the first row, i need:
Cell1 = Yellow
Cell2 = Blue
Cell3 = Green
Cell4 = Green
for the 2nd row i need:
Cell1 = Yellow
Cell2 = Blue
Cell3 = Green
Cell4 = Green
for the third row in need:
Cell1 = Red
Cell2 = Yellow
Cell3 = Blue
Cell4 = Blue
and finally for the forth row i need:
Cell1 = Red
Cell2 = Red
Cell3 = Yellow
Cell4 = Yellow
Does anybody know a way setting these to the desired colours?
please help!!!!!!
--
Thanks in advance,
Dave HuntDustpanDave,
According to the "Hitchhiker's Guide to SQL Reporting Services" book, page
433-436, you'll have to use RunningValue and CountDistinct within a Matrix.
They say:
1) Add a Row Gropu called RowColor and give it a grouping expression of "=1"
2) Find the textbox for RowColor and enter the expression
"=RunningValue(Fields!<columngroupname>.Value & Fields!<2ndColumnGroup>.Value
..., CountDistinct, Nothing)"
3) Then enter an expression into the background color for all of the fields
in question: "IIF(RunningValue(Fields!<ColumnGroupName>.Value &
Fields!<2ndColumnGroup>.Value & ..., CountDistinct, Nothing) mod 2, "Color1",
"Color1")
4) The ROWColor Textbox MUST remain visible (you can't hide it), but you can
shrink it's height, set the font to 1 pt, zero out your padding and/or set
the main Color property to the color of your background.
I hope this helps. I haven't done this in a Matrix yet. I've just used the
simpler format for table rows. The book is pretty decent and has helped me a
lot. I'd advise buying a copy, or at least buying a SQL RS book. Don't get
the one published by WROK, though. It's not the best of the available
material.
Catadmin
--
MCDBA, MCSA
Random Thoughts: If a person is Microsoft Certified, does that mean that
Microsoft pays the bills for the funny white jackets that tie in the back?
@.=)
"DustpanDave" wrote:
> Hi All
> I have a matrix that goes no bigger than 4 colums and 4 rows big.
> I need to have different colours for certain cells within the matrix.
> e.g for the first row, i need:
> Cell1 = Yellow
> Cell2 = Blue
> Cell3 = Green
> Cell4 = Green
> for the 2nd row i need:
> Cell1 = Yellow
> Cell2 = Blue
> Cell3 = Green
> Cell4 = Green
> for the third row in need:
> Cell1 = Red
> Cell2 = Yellow
> Cell3 = Blue
> Cell4 = Blue
> and finally for the forth row i need:
> Cell1 = Red
> Cell2 = Red
> Cell3 = Yellow
> Cell4 = Yellow
> Does anybody know a way setting these to the desired colours?
> please help!!!!!!
> --
> Thanks in advance,
> Dave Hunt|||Oh, I forgot to mention, this is to get alternating rows of color. You'll
have to play with it to get specific cell colors. Also, look up RowNumber()
function in BOL.
Catadmin
--
MCDBA, MCSA
Random Thoughts: If a person is Microsoft Certified, does that mean that
Microsoft pays the bills for the funny white jackets that tie in the back?
@.=)
"DustpanDave" wrote:
> Hi All
> I have a matrix that goes no bigger than 4 colums and 4 rows big.
> I need to have different colours for certain cells within the matrix.
> e.g for the first row, i need:
> Cell1 = Yellow
> Cell2 = Blue
> Cell3 = Green
> Cell4 = Green
> for the 2nd row i need:
> Cell1 = Yellow
> Cell2 = Blue
> Cell3 = Green
> Cell4 = Green
> for the third row in need:
> Cell1 = Red
> Cell2 = Yellow
> Cell3 = Blue
> Cell4 = Blue
> and finally for the forth row i need:
> Cell1 = Red
> Cell2 = Red
> Cell3 = Yellow
> Cell4 = Yellow
> Does anybody know a way setting these to the desired colours?
> please help!!!!!!
> --
> Thanks in advance,
> Dave Hunt|||Thanks for you help, having a look in the Hitchhikers guide now.
i have tried that but i will give it another go
cheers
dave
--
Thanks in advance,
Dave Hunt
"Catadmin" wrote:
> Oh, I forgot to mention, this is to get alternating rows of color. You'll
> have to play with it to get specific cell colors. Also, look up RowNumber()
> function in BOL.
> Catadmin
> --
> MCDBA, MCSA
> Random Thoughts: If a person is Microsoft Certified, does that mean that
> Microsoft pays the bills for the funny white jackets that tie in the back?
> @.=)
>
> "DustpanDave" wrote:
> > Hi All
> >
> > I have a matrix that goes no bigger than 4 colums and 4 rows big.
> >
> > I need to have different colours for certain cells within the matrix.
> >
> > e.g for the first row, i need:
> >
> > Cell1 = Yellow
> > Cell2 = Blue
> > Cell3 = Green
> > Cell4 = Green
> >
> > for the 2nd row i need:
> > Cell1 = Yellow
> > Cell2 = Blue
> > Cell3 = Green
> > Cell4 = Green
> >
> > for the third row in need:
> > Cell1 = Red
> > Cell2 = Yellow
> > Cell3 = Blue
> > Cell4 = Blue
> >
> > and finally for the forth row i need:
> > Cell1 = Red
> > Cell2 = Red
> > Cell3 = Yellow
> > Cell4 = Yellow
> >
> > Does anybody know a way setting these to the desired colours?
> > please help!!!!!!
> > --
> > Thanks in advance,
> > Dave Hunt|||Perfect, thanks also :-)
This is a problem I've been having and how have it fixed :-)
Sunday, March 11, 2012
Bacground Color of group
ie i am grouping in a product type that also has a product numbers & value
on the same line. Since there is more than 1 product type there is multiple
rows within the group.
I have tried the formula iif(rownumber(nothing) Mod 2, "Red", "White")
But this doesnt seem to work.Although I do not know the answer, perhaps the problem is related to
rownumber(nothing)... I think the rownumber function applies to rows in the
data set... and I wonder if the GROUP lines do not get a rownumber with
(nothing) as the parameter... You might add the function to display in the
group field to check its value...
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Tango" <Tango@.discussions.microsoft.com> wrote in message
news:23069475-AA6E-42BA-9211-321A65D4C3CE@.microsoft.com...
> How do a change the alternate rows within a group.
> ie i am grouping in a product type that also has a product numbers & value
> on the same line. Since there is more than 1 product type there is
> multiple
> rows within the group.
> I have tried the formula iif(rownumber(nothing) Mod 2, "Red", "White")
> But this doesnt seem to work.|||Thanks Wayne,
I would have thought this to be a common problem...
"Wayne Snyder" wrote:
> Although I do not know the answer, perhaps the problem is related to
> rownumber(nothing)... I think the rownumber function applies to rows in the
> data set... and I wonder if the GROUP lines do not get a rownumber with
> (nothing) as the parameter... You might add the function to display in the
> group field to check its value...
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Tango" <Tango@.discussions.microsoft.com> wrote in message
> news:23069475-AA6E-42BA-9211-321A65D4C3CE@.microsoft.com...
> > How do a change the alternate rows within a group.
> >
> > ie i am grouping in a product type that also has a product numbers & value
> > on the same line. Since there is more than 1 product type there is
> > multiple
> > rows within the group.
> >
> > I have tried the formula iif(rownumber(nothing) Mod 2, "Red", "White")
> >
> > But this doesnt seem to work.
>
>
Sunday, February 19, 2012
avg of timestamp
I have a timestamp column with format 00:00:00, and I want to get the
average time of all rows for that column.
When I try it, I get this error:
The average aggregate operation cannot take a timestamp data type as an
argument.
Thanks!
A timestamp is a point in time. So averaging is impossible.
This means that you would have to define the averaging formula yourself.
Let's assume all your datetime columns have the date 1900-01-01. In that
case you might use the formula:
SELECT
DATEADD(second,AVG(DATEDIFF(second,'19000101',MyDa teColumn)),'19000101')
FROM MyTable
HTH,
Gert-Jan
chrismtoth@.gmail.com wrote:
> Is it possible to use AVG with timestamp?
> I have a timestamp column with format 00:00:00, and I want to get the
> average time of all rows for that column.
> When I try it, I get this error:
> The average aggregate operation cannot take a timestamp data type as an
> argument.
> Thanks!
avg of timestamp
I have a timestamp column with format 00:00:00, and I want to get the
average time of all rows for that column.
When I try it, I get this error:
The average aggregate operation cannot take a timestamp data type as an
argument.
Thanks!A timestamp is a point in time. So averaging is impossible.
This means that you would have to define the averaging formula yourself.
Let's assume all your datetime columns have the date 1900-01-01. In that
case you might use the formula:
SELECT
DATEADD(second,AVG(DATEDIFF(second,'19000101',MyDateColumn)),'19000101')
FROM MyTable
HTH,
Gert-Jan
chrismtoth@.gmail.com wrote:
> Is it possible to use AVG with timestamp?
> I have a timestamp column with format 00:00:00, and I want to get the
> average time of all rows for that column.
> When I try it, I get this error:
> The average aggregate operation cannot take a timestamp data type as an
> argument.
> Thanks!
avg of timestamp
I have a timestamp column with format 00:00:00, and I want to get the
average time of all rows for that column.
When I try it, I get this error:
The average aggregate operation cannot take a timestamp data type as an
argument.
Thanks!A timestamp is a point in time. So averaging is impossible.
This means that you would have to define the averaging formula yourself.
Let's assume all your datetime columns have the date 1900-01-01. In that
case you might use the formula:
SELECT
DATEADD(second,AVG(DATEDIFF(second,'1900
0101',MyDateColumn)),'19000101')
FROM MyTable
HTH,
Gert-Jan
chrismtoth@.gmail.com wrote:
> Is it possible to use AVG with timestamp?
> I have a timestamp column with format 00:00:00, and I want to get the
> average time of all rows for that column.
> When I try it, I get this error:
> The average aggregate operation cannot take a timestamp data type as an
> argument.
> Thanks!
AVG by columns not by rows
rows.
E.g.
col1 col2 avg
--
2 2 2.0
3 2 2.5
I found something that requires manual sum of every column and than
dividing with number of nonzero an nonnull columns. I ended using tons
of case when... statements.
Is there any simple solution?Assuming you have a PK on your table
SELECT PK, AVG(AvgCol)
FROM
(SELECT PK, C1 AS AvgCol
FROM YourTable
UNION
SELECT PK, C2
FROM YourTable) T
GROUP BY PK
Regards
Roji. P. Thomas
http://toponewithties.blogspot.com
<milan.letic@.gmail.com> wrote in message
news:1151930480.771154.61470@.v61g2000cwv.googlegroups.com...
> Hello is there a way to calculate Average values for columns not for
> rows.
> E.g.
> col1 col2 avg
> --
> 2 2 2.0
> 3 2 2.5
> I found something that requires manual sum of every column and than
> dividing with number of nonzero an nonnull columns. I ended using tons
> of case when... statements.
> Is there any simple solution?
>|||If you need the entire original row, as I suspect you will, you will
need to join this back to the orignal table:
SELECT T.KeyCol,
AvgX = AVG(CASE WHEN N.X = 1 AND T.col1 <> 0 THEN T.col1
WHEN N.X = 2 AND T.col2 <> 0 THEN T.col2
WHEN N.X = 3 AND T.col3 <> 0 THEN T.col3
WHEN N.X = 4 AND T.col4 <> 0 THEN T.col4
WHEN N.X = 5 AND T.col5 <> 0 THEN T.col5
END)
FROM TheTable as T,
(select 1 as X UNION ALL
select 2 UNION ALL
select 3 UNION ALL
select 4 UNION ALL
select 5) as N
GROUP BY T.KeyCol
Also, your sample data appears to start with integer values but the
average is to one decimal place, so it appears some conversion before
the AVG is applied will be required.
Roy Harvey
Beacon Falls, CT
On 3 Jul 2006 05:41:20 -0700, milan.letic@.gmail.com wrote:
>Hello is there a way to calculate Average values for columns not for
>rows.
>E.g.
>col1 col2 avg
>--
>2 2 2.0
>3 2 2.5
>I found something that requires manual sum of every column and than
>dividing with number of nonzero an nonnull columns. I ended using tons
>of case when... statements.
>Is there any simple solution?|||If your table has a primary key, you can unpivot the result and group by the
primary key and then join the result to the original table.
create table dbo.t1 (
pk int not null identity primary key,
c1 int,
c2 int
)
go
insert into dbo.t1(c1, c2) values(2, 2)
insert into dbo.t1(c1, c2) values(3, 2)
go
select
t1.pk,
t1.c1,
t1.c2,
t2.col_avg
from
dbo.t1
inner join
(
select
a.pk,
avg(cast(
case b.c1
when 1 then a.c1
when 2 then a.c2
end as numeric(5, 2))) as col_avg
from
dbo.t1 as a
cross join
(select 1 as c1 union all select 2) as b
group by
a.pk
) as t2
on t1.pk = t2.pk
go
drop table dbo.t1
go
AMB
"milan.letic@.gmail.com" wrote:
> Hello is there a way to calculate Average values for columns not for
> rows.
> E.g.
> col1 col2 avg
> --
> 2 2 2.0
> 3 2 2.5
> I found something that requires manual sum of every column and than
> dividing with number of nonzero an nonnull columns. I ended using tons
> of case when... statements.
> Is there any simple solution?
>|||Guys, thank you. But, I don't understand your code. I don't know what
it does, which is more efficient.. I'm afraid I'll have to use my old
version.
Alejandro Mesa wrote:
> If your table has a primary key, you can unpivot the result and group by t
he
> primary key and then join the result to the original table.
> create table dbo.t1 (
> pk int not null identity primary key,
> c1 int,
> c2 int
> )
> go
> insert into dbo.t1(c1, c2) values(2, 2)
> insert into dbo.t1(c1, c2) values(3, 2)
> go
> select
> t1.pk,
> t1.c1,
> t1.c2,
> t2.col_avg
> from
> dbo.t1
> inner join
> (
> select
> a.pk,
> avg(cast(
> case b.c1
> when 1 then a.c1
> when 2 then a.c2
> end as numeric(5, 2))) as col_avg
> from
> dbo.t1 as a
> cross join
> (select 1 as c1 union all select 2) as b
> group by
> a.pk
> ) as t2
> on t1.pk = t2.pk
> go
> drop table dbo.t1
> go
>
> AMB
> "milan.letic@.gmail.com" wrote:
>|||Hi There,
Roji has already given you a solution , I had changed it minorly by
using UNION ALL instead of UNION and added where clause although it is
not required as much.
Here R is a value that uniquely identifies a row (i.e Primary key )
Create view tmpData3
as
Select 1 R,null a,2 b, 3 c
Union
Select 2 R,1 a,null b, 3 c
Union
Select 3 R,1 a,2 b, null c
Union
Select 4 R,1 a,null b, null c
Go
Select R,avg(col) From
(
Select R,cast(a as numeric) col from tmpData3 where a>0
Union All
Select R,b from tmpData3 where b>0
Union All
Select R,c from tmpData3 where c>0
)X group by R
drop view tmpData3
With Warm regards
Jatinder Singh
http://jatindersingh.blogspot.com
milan.letic@.gmail.com wrote:
> Guys, thank you. But, I don't understand your code. I don't know what
> it does, which is more efficient.. I'm afraid I'll have to use my old
> version.
>
> Alejandro Mesa wrote:
Thursday, February 16, 2012
Averaging a set of columns in the same table
Each column represents a set of data from a different source.
Anywhere from 1 to 100 of the columns may contain data (empty will be null)
I need to find a way to average accross the rows depending on the number of
rows which have data
Ie for first row
(Col1 + Col2 + Ccol3...Col34) / 34 where only col1 to col34 have data.
or
(Col1 + Col2 + Ccol3) / 3 where only col1 to col3 have data.
Note number of rows will always be the same for every column appx 20000
I know I could convert the horizontal data into vertical but this will mean
a table of over 2million rows. Other constarints force me to aviod this.
Any ideas ?Hi
Normalize the table and then you can do averages over the groups (as you now
have rows) using the group by clause.
Your table design is not conducive to easy programming.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Jinx1966" <Jinx1966@.discussions.microsoft.com> wrote in message
news:D9C74420-C0A1-400B-8518-3CE1BE0B19D5@.microsoft.com...
>I have a table which has 100 columns with appx 20000 rows
> Each column represents a set of data from a different source.
> Anywhere from 1 to 100 of the columns may contain data (empty will be
> null)
> I need to find a way to average accross the rows depending on the number
> of
> rows which have data
> Ie for first row
> (Col1 + Col2 + Ccol3...Col34) / 34 where only col1 to col34 have data.
> or
> (Col1 + Col2 + Ccol3) / 3 where only col1 to col3 have data.
>
> Note number of rows will always be the same for every column appx 20000
> I know I could convert the horizontal data into vertical but this will
> mean
> a table of over 2million rows. Other constarints force me to aviod this.
> Any ideas ?|||> I know I could convert the horizontal data into vertical but this will mean
> a table of over 2million rows.
And... ?
> Other constarints force me to aviod this.
What constraints? This design is likely to be an awful nightmare and
performance bottleneck. The cost of supporting it is surely far greater
than that of fixing it.
but ...
(COALESCE(col1,0)+COALESCE(col2,0)+COALESCE(col3,0) ...)/
(CASE WHEN col1 IS NOT NULL THEN 1 END +
CASE WHEN col2 IS NOT NULL THEN 1 END +
CASE WHEN col3 IS NOT NULL THEN 1 END +
...)
(yuck!)
--
David Portas
SQL Server MVP
--|||Thanks Mike.
"Mike Epprecht (SQL MVP)" wrote:
> Hi
> Normalize the table and then you can do averages over the groups (as you now
> have rows) using the group by clause.
> Your table design is not conducive to easy programming.
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> IM: mike@.epprecht.net
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
> "Jinx1966" <Jinx1966@.discussions.microsoft.com> wrote in message
> news:D9C74420-C0A1-400B-8518-3CE1BE0B19D5@.microsoft.com...
> >I have a table which has 100 columns with appx 20000 rows
> > Each column represents a set of data from a different source.
> > Anywhere from 1 to 100 of the columns may contain data (empty will be
> > null)
> >
> > I need to find a way to average accross the rows depending on the number
> > of
> > rows which have data
> >
> > Ie for first row
> > (Col1 + Col2 + Ccol3...Col34) / 34 where only col1 to col34 have data.
> > or
> > (Col1 + Col2 + Ccol3) / 3 where only col1 to col3 have data.
> >
> >
> > Note number of rows will always be the same for every column appx 20000
> >
> > I know I could convert the horizontal data into vertical but this will
> > mean
> > a table of over 2million rows. Other constarints force me to aviod this.
> >
> > Any ideas ?
>
>|||Thanks David. I quite agree with your comments. Only you know how it can be,
small machines with small resources run by people with small brains and ears.
Now I have your and Mikes opinions I can get this issue fixed the proper
way...
Appreciate your time.
Regards
"David Portas" wrote:
> > I know I could convert the horizontal data into vertical but this will mean
> > a table of over 2million rows.
> And... ?
> > Other constarints force me to aviod this.
> What constraints? This design is likely to be an awful nightmare and
> performance bottleneck. The cost of supporting it is surely far greater
> than that of fixing it.
> but ...
> (COALESCE(col1,0)+COALESCE(col2,0)+COALESCE(col3,0) ...)/
> (CASE WHEN col1 IS NOT NULL THEN 1 END +
> CASE WHEN col2 IS NOT NULL THEN 1 END +
> CASE WHEN col3 IS NOT NULL THEN 1 END +
> ...)
> (yuck!)
> --
> David Portas
> SQL Server MVP
> --
>
Average problem
I've a subtotal row in a matrix. I do an average of a column but the avg
function return me the average of all results of each rows. In fact, I want
do the average of each colums except where the results is equal to 0.
How can I do that?Aggregate functions like Sum, Count, Avg, etc. only consider values which
are not null.
Try this:
=Avg(iif(Fields!X.Value = 0, Nothing, Fields!X.Value))
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Seb" <Seb@.discussions.microsoft.com> wrote in message
news:AA16A434-5BB4-4D03-B9E8-4C4D5224BB1D@.microsoft.com...
> Hi,
> I've a subtotal row in a matrix. I do an average of a column but the avg
> function return me the average of all results of each rows. In fact, I
want
> do the average of each colums except where the results is equal to 0.
> How can I do that?
Average of fields in a record
I am looking for a simple way to average fields in a record..not rows, but fields, using a procedure. If one of the fields is null, then it needs to be excluded from the average.
Any ideas?
Help would be really appreciated!!
Thanks.
NickieOriginally posted by ngillis
Hi.
I am looking for a simple way to average fields in a record..not rows, but fields, using a procedure. If one of the fields is null, then it needs to be excluded from the average.
Any ideas?
Help would be really appreciated!!
Thanks.
Nickie
If it is permanent table - you can use system tables (syscolumns,sysobjects) for creating dynamic query and calculating.
But, I afraid, there is something wrong with db design if you need to do things like this.|||Hi Snail.
Please explain. My tables are the results of survey information that is entered online by clients. I need to calculate the averages of groups of questions that they answered. One survey is one record in the database, which includes the groups of records.
What would be a better way to do this? I can't change it now as the survey is live..but it would be helpful for future use.
I don't really know much about sysobjects. and help is not that helpful. Any ideas where I can get more information?
Thanks.
Nickie|||Whoops..where I said "One survey is one record in the database, which includes the groups of records." I meant to say the groups of questions.
Thanks.|||Hello Nickie,
an easy way to calculate averages of certain fields would be
select (coalesce(field_1, 0) + coalesce(field_2, 0))/number_of_fields
from table
BUT, this query will replace every NULL value with 0 (or every other number you put in the COALESCE statement).
Maybe this "workaround" will help out. If not post again!
Greetings,
Carsten
Sunday, February 12, 2012
Autoslicing not working
I have around 36 partitions in the 2005 cube. Each partition is roughly 20M fact rows.
The partitions are differentiated by a date member dimension.
When I run a query which selects by a distinct date, SSAS tries to scan all partitions (for inclusions?). This introduces a huge performance impact. It takes many seconds to run a single query.
I have aggregations designed specifically for relevant dimensions. The Profiler shows that SSAS reads from aggregations. It does not read from facts.
The storage mode is MOLAP.
Do I need to use the partition slice property ? I am seeing on forums from time to time that this attribute is not used in MOLAP.
I just need to make sure that my queries are fast.
I don't see where it could hurt to set this property, though BOL indicates this is only used by SSAS for ROLAP partitions. I thought I had heard that with MOLOP and/or HOLAP, that SSAS maintained an internal set of information regarding the contents of a slice that would handle this function for you. Maybe someone else out there could chime in on this one.
Regarding the query you specify above, are you specifying a date member from the specific cube dimension used to partition your cube? You probably are but it wasn't explicitly stated. Date dimensions are often used in a role-playing capacity which introduces some confusion.
Thanks,
Bryan
can anyone clarify if the Slice property on Partition is used in MOLAP or not?
I checked info....xml files for my slicing dimension min/max values and they seem correct, however with explicit queries, SSAS still reads a bunch of partitions...