Sorting expressions on SSRS - reporting-services

I've created a table on Visual studio (SSRS) that has 1 parent group and 2 child groups with drilldown, one of the child groups is a union of 2 columns from the sql script , Below is the expression used on that one:
=IIF(Count(Fields!Terminal_ID.Value)>1 ,
Fields!Tier_1_Customer.Value & " (" & Count(Fields!Terminal_ID.Value) & " POS terminals)",
Fields!Tier_1_Customer.Value & " (" & Count(Fields!Terminal_ID.Value) & " POS terminal)")
The result of that will be something like:
Store # 4 ( 1 device)
Store # 3 ( 2 devices)
Store # 8 ( 9 devices)
What I cannot figure out how to do is how to apply a sort so it can display the data from z to a as below:
Store # 8 ( 9 devices)
Store # 3 ( 2 devices)
Store # 4 ( 1 device)
I've applied different sorting options to the column but it does not work , any suggestion?

Go in to the child group properties. In the sort tab, use this expression:
=Count(Fields!Terminal_ID.Value)
Set it to descending (Z-A). This will sort the details of this group by this value.

Related

How to use 2 series in a chart with mysql query result on vb.net?

I have a table named 'tbl_mortuarytrans' with (branch, regtype) columns in it, which regtype has 'NEW' or 'RNW' values. How to make a query for it on mysql that will have result total number of rows in every regtype(NEW,RNW) group by branch and put the result on a chart, Series1 will be for NEW and Series 2 will be for RNW?
I have tried a query and it gave correct result but for NEW regtype only.
How can i put a subquery for it to make a resultset like this...
Branch | NEW | RNW
SELECT COUNT(\*) AS NEW, branch
FROM `tbl_mortuarytrans`
WHERE MONTH(registered) = '" & cmbMonth.SelectedIndex & "' AND YEAR(registered) = '" & txtYear.Text.Trim & "' AND `regtype` LIKE 'NEW'
GROUP BY `branch`

MDX - comma-separated column to summarize values across time dimension (rows)

The below MDX query
WITH
MEMBER [Measures].[GM%] AS
IIF
(
[Measures].[Revenue] > 2
,
([Measures].[Revenue] - [Measures].[Cost]) / [Measures].[Revenue] * 100
,NULL
)
SELECT
CrossJoin
(
LastPeriods
(5
,[Date.YQM].[2018].LastChild
)
,[Measures].[GM%]
) ON COLUMNS
,NON EMPTY
{Order([SP].Children,[Measures].[Revenue],DESC)} ON ROWS
FROM [GM_SP];
Gives me the following tabular output:
Table output
Question: How can I add a column to the end that summarizes the values across the 5 Quarters?
I need this output comma-separated as it is used for rendering a sparkline within the table. (Pentaho CDE used to render).
Example Column 7
row 1: 100,,,,
row 2: 97.82535574475716, 95.83261932552514,
96.51941349723123, 96.77026598200818, 97.85452666266234

Add Column in Table with conditional in block WHERE

I was doing a query with MySQL to save all objects returned, but I'd like identify these objects based in statements of the block WHERE, that is, if determined object to satisfy the specific characteristic I'd like create one column and in this column I assignment the value 0 or 1 in the row corresponding the object if it satisfy or not satisfy these characteristic.
This is my script:
SELECT
s.id, al.ID, al.j, al.k, al.r, gal.i
FROM
datas as al
WHERE
AND s.id = al.ID
AND al.j between 1 and 1
AND al.k BETWEEN 15 and 16
AND al.r BETWEEN 67 and 72
The script above is working perfectly and I can to save all objects which it return.
So, I'd like to know if is there a way add in the query above, on block WHERE, the following statement,
( Flags & (dbo.environment('cool') +
dbo.environment('ok') -
dbo.environment('source')) ) = 25
and ((al_pp x al_pp1)-0.5/3=11
and determined the objects that satisfy or not these condition with 0 or 1 in a new column created in Table saved.
I read some tutorials about this and saw some attempts with IF, CASE, ADD COLUMN or WHEN, but none of these solved.
Thanks in advance
MySQL has if function, see here
So you can simply use it in your query:
SELECT IF(( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petroRad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4
, 1 --// VALUE IF TRUE
, 0 --// VALUE IF FALSE
) as conditional_column, ... rest of your query

Expanding a range of phone numbers in Access

I have a table with phone numbers. One column has the first number in a range. The next column has the last four digits in that range. How do I create a row for each individual number?
Example:
202-366-1234 (phone number from)
next column has 1240 (phone number to)
I would like to have each phone number on a separate row. So they would look like this.
202-366-1234
202-366-1235
202-366-1236
202-366-1237
202-366-1238
202-366-1239
202-366-1240
Any ideas?
Create a variation of a typical "numbers" table to hold all of the possible last-four-digits, e.g.
[PhoneSuffix]
suffix
------
0000
0001
0002
...
9998
9999
then for an input table like this
[Table1]
ID PhoneFrom PhoneTo
-- ------------ -------
1 202-366-1234 1240
2 416-555-1212 1221
you could use a query like this:
SELECT Left(t1.PhoneFrom, 8) & ps.suffix AS PhoneNo
FROM Table1 t1, PhoneSuffix ps
WHERE ps.suffix Between Right(t1.PhoneFrom, 4) And t1.PhoneTo
You can use this fancy Cartesian (multiplying) query which doesn't require new tables:
SELECT DISTINCT
10*Abs([Deca].[id] Mod 10)+Abs([Uno].[id] Mod 10) AS Id,
Left([StartNumber],8) & CStr(Val(Right([StartNumber],4))+[Factor]) AS PhoneNumber
FROM
msysobjects AS Uno,
msysobjects AS Deca
WHERE
(((10*Abs([Deca].[id] Mod 10)+Abs([Uno].[id] Mod 10))<=Val([EndNumber])-Val(Right([StartNumber],4))));

How to create a computed column name using another column's value (sql server 2008)

I need to use the value of a column in the name of a new column....this is the line I need help with:
Count([DepartmentName]) As [[DepartmentName] + "Emails"]
Code:
SELECT
[CustomerId],
#MetricMonth AS "MetricMonth",
#MetricYear AS "MetricYear",
[LeadType], [DeviceTypeId], [DepartmentName],
Count([DepartmentName]) As [[DepartmentName] + "Emails"]
FROM
[myTable]
WHERE
LeadType = #LeadType
AND _CreateDate BETWEEN #StartDateTime AND #EndDateTime
GROUP BY
[CustomerId], [LeadType], [DeviceTypeId], [DepartmentName]
The reason for the need is that the receiving table has columns labeled as such and this seems like the cleanest way to do it. There are 16 possible values for DepartmentName so I don't want to have a bunch of case statements.
Here's a sample of the result. There will be multiple groups because of DepartmentName and DeviceTypeId.
CustomerId MetricMonth MetricYear LeadType DeviceTypeId DepartmentName NewName
28590 4 2014 Email 1 New 9
36980 4 2014 Email 1 Finance 3
876 4 2014 Email 1 New 9
Thanks!
You in effect want a column name that has multiple values, ie a column with multiple names, which is just impossible in any flavor of SQL, afaik.
Short of that, you have two options:
if you really want columns with names like "Department1 Emails" then you will have to pivot the data (and you'll have to hard-code all the Department Names). If that is what you want see here.
if you just want a column called "Department Emails" with values such as "Department1 Emails: 30" then you can do this:
SELECT [DepartmentName], [DepartmentName] + ' Emails: ' + CAST(COUNT([DepartmentName]) AS VARCHAR(20))
FROM [myTable]
GROUP BY [DepartmentName]