Showing posts with label expression. Show all posts
Showing posts with label expression. Show all posts

Sunday, March 25, 2012

Calculated fields in Matrix

Hi!

I have a calculated field in a dataset, Productivity, defined by this expression:

Fields!BCM.Value/Fields!MINUTES.Value

When I use it on a table, everything works fine. But when I try to use it on a matrix, I get an error
(#ERROR) on the field.
Why does it happen? Can't I use calculated fields on matrix?

Thank you!

Dear,

Sure , u will get the error beause u are using the field in matrix but when u define the function u are not passing the matrix refrence.

eg:

=iif(inscope(Sum(Fields!OrderQty.Value, "MatrixSource")),sum(Fields!OrderQty.Value),sum(Fields!OrderQty.Value)/Sum(Fields!OrderQty.Value, "MatrixSource"))

HTH

from

sufian

Tuesday, March 20, 2012

Calculate expression - error

The field name in my column 'Num' (1, 2, 3 and 4),
the data i am using is a 'price' field, so under column name 1 my data is
'10', under 2 is '20', under 3 is '60' and under 4 is '90'.
On my next table i need to create data expression. Some thing like this;
'Price' where 'Num' = 1 devide by 'Price' where 'Num' > 1. So in this case
my data should look like this;
under column 1 nothing
under column 2 would be '2'
under column 3 would be '6'
under column 4 would be '9'
=IIF(Fields!Num.Value = 1, Sum(Fields!Price.Value)/Sum(Fields!Price.Value),
Fields!Num.Value > 1)Although I am not truly sure I understand your question, I'll give a stab..
IIF(Fields!Num.Value = 1
,Fields!Price.Value
, Sum(Fields!Num.Value)/Sum(Fields!Price.Value)
)
If Num = 1 Return the Price, Otherwise return the Num/Price...
--
Wayne Snyder MCDBA, SQL Server MVP
Mariner, Charlotte, NC
I support the Professional Association for SQL Server ( PASS) and it''''s
community of SQL Professionals.
"JT" wrote:
> The field name in my column 'Num' (1, 2, 3 and 4),
> the data i am using is a 'price' field, so under column name 1 my data is
> '10', under 2 is '20', under 3 is '60' and under 4 is '90'.
> On my next table i need to create data expression. Some thing like this;
> 'Price' where 'Num' = 1 devide by 'Price' where 'Num' > 1. So in this case
> my data should look like this;
> under column 1 nothing
> under column 2 would be '2'
> under column 3 would be '6'
> under column 4 would be '9'
> =IIF(Fields!Num.Value = 1, Sum(Fields!Price.Value)/Sum(Fields!Price.Value),
> Fields!Num.Value > 1)|||On Feb 12, 5:40=A0pm, JT <J...@.discussions.microsoft.com> wrote:
> The field name in my column 'Num' (1, 2, 3 and 4),
> the data i am using is a 'price' field, so under column name 1 my data is
> '10', under 2 is =A0'20', under 3 is '60' and under 4 is '90'.
> On my next table i need to create data expression. Some thing like this;
> 'Price' where 'Num' =3D 1 devide by 'Price' where 'Num' > 1. So in this ca=se
> my data should look like this;
> under column 1 nothing
> under column 2 would be '2'
> under column 3 would be '6'
> under column 4 would be '9'
> =3DIIF(Fields!Num.Value =3D 1, Sum(Fields!Price.Value)/Sum(Fields!Price.Va=lue),
> Fields!Num.Value > 1)
The problem is that when you group by the Num (by using it in a
Column), then the values that are in scope in the Details area of the
Matrix are only the rows that are available in that group. To get
around this, you have to provide a value for the Scope Parameter in
the Sum function to to a Sum over all rows in the Dataset.
Assuming your dataset is named "DataSet1", your column is grouping on
Fields!Num.Value, then you can get the desired output with the
following expression in the Details area:
=3DIIF( Fields!Num.Value =3D 1, Nothing,
Sum( Fields!Price.Value ) / Sum( IIF(Fields!Num.Value =3D 1, Fields!
Price.Value, Nothing ), "DataSet1" ) )
-- Scott

Calculate Expression

Hello,
I have a query that I am using to calculate an order filled rate.
One of my columns is OrderNo. to get the total orders for a date I take the
order no. and just count to get a total for that column.
Now the trick is I need to subtract from that count cancelled orders.
How would I do that?
I have tried:
Count(Fields!order_type.Value - Fields!cancel_qty.Value) and
Count(Fields!order_type.Value) - Fields!cancel_qty.Value
No luck either way.
I would appreciate any help that you could give. Thanks,
Kevindepends, perhaps:
count(Fields!order_type:Value) - sum(Fields!cancel_qty.Value)
might work.
"Kevin Eck" wrote:
> Hello,
> I have a query that I am using to calculate an order filled rate.
> One of my columns is OrderNo. to get the total orders for a date I take the
> order no. and just count to get a total for that column.
> Now the trick is I need to subtract from that count cancelled orders.
> How would I do that?
> I have tried:
> Count(Fields!order_type.Value - Fields!cancel_qty.Value) and
> Count(Fields!order_type.Value) - Fields!cancel_qty.Value
> No luck either way.
> I would appreciate any help that you could give. Thanks,
> Kevin
>
>|||Thanks Jimbo...
worked like a charm!!!
"Jimbo" <Jimbo@.discussions.microsoft.com> wrote in message
news:B167604A-34A2-4076-99A1-FF608AF774B5@.microsoft.com...
> depends, perhaps:
> count(Fields!order_type:Value) - sum(Fields!cancel_qty.Value)
>
> might work.
>
> "Kevin Eck" wrote:
>> Hello,
>> I have a query that I am using to calculate an order filled rate.
>> One of my columns is OrderNo. to get the total orders for a date I take
>> the
>> order no. and just count to get a total for that column.
>> Now the trick is I need to subtract from that count cancelled orders.
>> How would I do that?
>> I have tried:
>> Count(Fields!order_type.Value - Fields!cancel_qty.Value) and
>> Count(Fields!order_type.Value) - Fields!cancel_qty.Value
>> No luck either way.
>> I would appreciate any help that you could give. Thanks,
>> Kevin
>>
>>

Tuesday, February 14, 2012

But the documentation is NOT correct

The documentation says

ISNUMERIC returns 1 when the input expression evaluates to a valid
integer, floating point number, money or decimal type; otherwise it
returns 0. A return value of 1 guarantees that expression can be
converted to one of these numeric types.

(Cut and pasted from books online)

Yet the following, one of many, example shows this is not true.

select isnumeric(char(9))
select convert(int, char(9))

----
1

(1 row(s) affected)

Server: Msg 245, Level 16, State 1, Line 2
Syntax error converting the varchar value '' to a column of data type
int.

So, besides filtering every possible invalid character, how do you
convert dirty values without error. I am not concerned that I may loose
possibly valid values or convert suspect strings to 0 (zero). I just
want to run without raising an errorBooks Online is quite correct here, it just could be a bit clearer. The
significant word in the paragraph you posted is "or". ISNUMERIC returns
1 if the data is convertible to ANY of the datatypes listed. Try the
following, which will work:

SELECT CONVERT(MONEY, CHAR(9))

If you just want to convert positive integers then you can use LIKE to
determine whether a string contains only numerics:

SELECT CAST(col AS INTEGER)
FROM YourTable
WHERE col NOT LIKE '%[^0-9]%'

--
David Portas
SQL Server MVP
--|||By inference then CONVERT(MONEY, x) is the most 'tolerant' conversion.
Strings containing only numerics is also elegant.

Thanks for the tip|||(bilbo.baggins@.freesurf.ch) writes:
> By inference then CONVERT(MONEY, x) is the most 'tolerant' conversion.

Not necessarily:

SELECT convert(money, '1E1')

bombs. But isnumeric() returns 1.

isnumeric is a useless function.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp