SSRS: Open report with long URL parameters in new window - sql-server

I have question similar as Open SSRS URL in New Window, but one of my parameters has many values and the URL becomes too long. This parameter always equals such parameter in initial report.
How can I solve it? Can I make post request in "go to url" field or define parameter default value from initial report?

Here is how I reduce the amount of characters passed into my report URL with parameters. Since Microsoft Internet Explorer has a maximum uniform resource locator (URL) length of 2,083 characters you have to get creative.
First, add parameter values for all variables. The other option would be to use a defaults table.
Then union the parameter(s) to the datasets for your other parameters. This way you'll get the all option in your parameter dropdowns.
;WITH
teams_source
AS
(
SELECT tbl.* FROM (VALUES
( 2323304)
, ( 2323305)
, ( 2323306)
, ( 2323307)
, ( 2323308)
, ( 2323309)
, ( 2323310)
, ( 2323311)
, ( 2323312)
, ( 2323313)
, ( 2323314)
, ( 2323315)
, ( 2323316)
) tbl ([Teams])
)
SELECT [Teams], [TeamsFormat] = CAST([Teams] AS VARCHAR) FROM teams_source
UNION
SELECT [Teams] = #all_value_nbr, [TeamsFormat] = #all_value_text
ORDER BY 1
Then in the dataset for your report change the WHERE clause to check for the all variable.
WHERE
1=1
AND (#all_value_nbr IN(#Teams) OR [Teams] IN(#Teams))
When you build the URL with parameters, you can count the number of values.
IIF(Parameters!Teams.Count = Count(Fields!Teams.Value, "TeamsDataset"), "", "#Teams=" + Join(Parameters!Teams.Value, "#Teams="))

Related

Removing Blank Days from Power BI Chart

I have created a weekly request measure like so :
RequestsWeekly = var result= CALCULATE(
DISTINCTCOUNTNOBLANK(SessionRequests[RequestDateTime]),
FILTER('Date','Date'[WeekDate]=SELECTEDVALUE('DateSelector'[WeekDate],MAX('DateSelector'[WeekDate]))))+0
RETURN
IF ( NOT ISBLANK ( result ), result)
DateSelector is a standalone table (not connected to any other table in data model) that I have created for all the dates for a dropdown menu select for a Power BI Dasbboard. Unfortunately as there are less dates in the Date Selector table than the Date table, I get ...
Date table is the standard DATE table full of dates from 1970 to 2038. Date connects to Session Requests via a many to one relationships, single way filter. Session Requests is the main fact table.
I need to get rid of the blank row in my result set via DAX so it does not appear in my chart on the X axis. I have tried lots of different DAX combos like blank () and NOT ISBLANK. Do I need to create a table for the result set and then try to filter out the blank day there?
You should not check if the result is empty but if the VALUE ( Table[DayNameShort] ) exists for your current row context:
RequestsWeekly =
VAR result =
CALCULATE (
DISTINCTCOUNTNOBLANK ( SessionRequests[RequestDateTime] ),
FILTER (
'Date',
'Date'[WeekDate]
= SELECTEDVALUE (
'DateSelector'[WeekDate],
MAX ( 'DateSelector'[WeekDate] )
)
)
) + 0
RETURN
IF (
NOT ISBLANK (
VALUE ( Table[DayNameShort] ) -- put here correct table name
),
result
)

Convert Statement to Crystal Reports SQL Expression

I have a SQL command that works great in SQL Server. Here's the query:
SELECT TOP 1000
(
SELECT COUNT(LINENUM)
FROM OEORDD D1
WHERE D1.ORDUNIQ = OEORDD.ORDUNIQ
)
- (SELECT COUNT(LINENUM)
FROM OEORDD D1
WHERE D1.ORDUNIQ = OEORDD.ORDUNIQ
AND D1.LINENUM > OEORDD.LINENUM)
FROM OEORDD
ORDER BY ORDUNIQ, LINENUM
The query looks at the total lines on an order, then looks at the current "LINENUM" field. With the value of the LINENUM field, it looks to see how many lines have a greater LINENUM value on the order and subtracts it from the number of lines on an order to get the correct Line number.
When I try to add it as a SQL expression in version 14.0.2.364 as follows:
(
(
SELECT COUNT("OEORDD"."LINENUM")
FROM "OEORDD" "D1"
WHERE "D1"."ORDUNIQ" = "OEORDD"."ORDUNIQ"
)
- (SELECT COUNT("OEORDD"."LINENUM")
FROM "OEORDD" "D1"
WHERE "D1"."ORDUNIQ" = "OEORDD"."ORDUNIQ"
AND "D1"."LINENUM" > "OEORDD"."LINENUM"
)
)
I get the error "Column 'SAMDB.dbo.OEORDD.ORDUNIQ' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
If I try to add GROUP BY "OEORDD"."ORDUNIQ" at the end, I get "Incorrect syntax near the keyword 'GROUP'. I've tried adding "FROM OEORDD" at the end of query and it errors out on the word "FROM". I have the correct tables linked in the Database Expert.
EDIT --------------
I was able to get the first query working by getting rid of the alias, it's as follows:
(
SELECT COUNT(LINENUM)
FROM OEORDD
WHERE OEORDH.ORDUNIQ=OEORDD.ORDUNIQ)
)
However, I believe I need to use the alias in the second query to compare line numbers. I'm still stuck on that one.

How to write MDX Query for getting grouped results

I have Cube where data is aggregated and all I need to have count of records against each 2 digit zip code.
Attached image shows my cube hierarchies and measures.
I applied query like :
WITH MEMBER [Measures].NoOfConsignments as Count(([Consignment].[Target Address Name].[Target Address Name]))
select filter([Consignment].[Distribution Area].[Zip2], [Consignment].[Distribution Area].[Target Address Country] = "94") on rows,
{[Measures].NoOfConsignments} on columns
from [RebellOlap]
where ({[Consignment].[Distribution Area].[Target Address Country].&[94]})
but is throwing an error :
"The Distribution Area hierarchy already appears in the Axis1 axis"
I re-structured and formulated following sub-select query in the following way :
WITH MEMBER [Measures].NoOfConsignments as Count(([Consignment].[Target Address Name].[Target Address Name]))
Select
NON EMPTY [Measures].NoOfConsignments on columns,
NON EMPTY [Consignment].[Distribution Area].[Zip2] on rows
FROM (
SELECT {[Consignment].[Distribution Area].[Zip2],[Consignment].[Distribution Area].[Target Address Country].&[94]}
FROM [RebellOlap]
)
but it also returned me the 'ambiguity error'.
all I need Output in following manner
Edit
AllConsignments in Germany
All Consignments in Germany against specific Zip Code
I just applied filter for all zip codes and introduce "Range" as Operator with 'Filter Expression' and it worked!!
SELECT NON EMPTY { [Measures].[ConsignmentCount] } ON COLUMNS,
NON EMPTY { ([Consignment].[Distribution Area].[Zip2].ALLMEMBERS ) } ON ROWS
FROM ( SELECT ( [Consignment].[Distribution Area].[Zip2].&[94]&[0]&[01] : [Consignment].[Distribution Area].[Zip2].&[94]&[9]&[99] ) ON COLUMNS
FROM [RebellOlap])
Based on your edits, I feel below should work out for you:
WITH MEMBER Measures.NumConsignment as
COUNT
(
NonEmpty
(
[Consignment].[Target Address Name].[Target Address Name].MEMBERS,
([Consignment].[Distribution Area].CURRENTMEMBER, Measures.[Num. Consignments])
)
)
SELECT [Consignment].[Distribution Area].[Zip2].MEMBERS on 1,
Measures.NumConsignment ON 0
FROM
(
SELECT [Consignment].[Distribution Area].[Target Address Country].&[94] ON 0
FROM [RebellOlap]
)
While the rest of the code is pretty standard, there is one part which might need explanation.
NonEmpty
(
[Consignment].[Target Address Name].[Target Address Name].MEMBERS,
([Consignment].[Distribution Area].CURRENTMEMBER, Measures.[Num. Consignments])
)
This is returning a set of those Target addresses for the current zip for whom the num of consignments is not empty( i.e. <>0)

Filtration in the List based on "User!UserID"

Goal:
To make a filtration in the table list with support of "where" statement based on SSRS:s built-in function "User!UserID" in SSRS.
Problem:
I need apply the output value of the code
REPLACE
(
MID
(
User!UserID,
InStr(User!UserID,"\")+1,
Len(User!UserID)
),
".",
" "
)
in the dataset, inside of Where statement, but I retrieve error.
I also tried to apply the sourcecode as a variable and use it in the dataset, but the query designer complain that the variable do not exist. I'm using MDX code
What should I do?
WHERE
(
FILTER
(
xxxxxxxx.xxxxxxxx.ALLMEMBERS AS c,
c.Current.Name =
REPLACE
(
MID
(
User!UserID,
InStr(User!UserID,"\")+1,
Len(User!UserID)
),
".",
" "
)
)
)
1.
You apply the code
REPLACE
(
MID
(
User!UserID,
InStr(User!UserID,"\")+1,
Len(User!UserID)
),
".",
" "
)
in a new parameter, default value.
select dataset and go to the query designer and add a new parameter. The new parameter shall have same common with other data with similiar first and last name in from the dimension table.
3.add the parameter code in the query designer mode with mdx coding.

How do I search for multiple values in a column where I need to use wildcards?

In SQL Server, I need to search a column for multiple values, but I don't have the exact values, so I need to use wildcards as well.
My current query looks like this:
SELECT *
FROM table
WHERE fieldname in ( '%abc1234%',
'%cde456%',
'%efg8976%')
This doesn't return any results, and yet if I search for any one individual value, I find it, so I know they're in there. Short of doing multiple OR's, which is a bit unwieldy with several hundred values, is there a way to do this?
I'd also be interested to know why this query doesn't work, since the same query without the %'s works just fine (except for the small problem of only catching the few exact matches).
Look at using a Fulltext Index. That should do a much better job with your search, and make your "OR" problem a little nicer to boot:
SELECT *
FROM table
WHERE CONTAINS(fieldname, '"abc1234" OR "cde456" OR "efg8976"')
See also:
http://www.simple-talk.com/sql/learn-sql-server/full-text-indexing-workbench/
The reason the query doesn't work is that it looks for an exact match for fieldname within the list of values in the parens. It doen't do a LIKE comparison where the wildcards are taken into account.
So your query is equivalent to:
SELECT * from table
where fieldname = '%abc1234%' OR
fieldname = '%cde456%' OR
fieldname = '%efg8976%'
Obviously not what you want.
select table.* from (
table join
( select * from values (
( '%abc1234%' ), ( '%cde456%' ), ( '%efg8976%' )
) ) as search( exp ) on 0 = 0
) where fieldname like exp
or perhaps
select table.* from
table join
( select * from values (
( '%abc1234%' ), ( '%cde456%' ), ( '%efg8976%' )
) ) as search( exp )
on fieldname like exp
modulo some syntax I'm sure.
The point being that this comes close to allowing the list of values to be the only parameter.

Resources