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.
Related
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
)
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="))
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.
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.
I have a correct MDX-query:
SELECT NON EMPTY { [Measures].[IssueOpened] } ON COLUMNS,
NON EMPTY { ([Projects].[Id].[Id].ALLMEMBERS * [Priorities].[Id].[Id].ALLMEMBERS ) } ON ROWS
FROM [Reports]
WHERE [CreatedOn].[Date].&[2010-01-01T00:00:00]:[CreatedOn].[Date].&[2010-02-01T00:00:00]
I need to create SSRS-report with filter on CreatedOn dimension.
Here is my non-working solution:
I transform query to:
SELECT NON EMPTY { [Measures].[IssueOpened] } ON COLUMNS,
NON EMPTY { ([Projects].[Id].[Id].ALLMEMBERS * [Priorities].[Id].[Id].ALLMEMBERS ) } ON ROWS
FROM (SELECT (STRTOSET(#CreatedOnDate, CONSTRAINED) ) ON COLUMNS
FROM [Reports])
CreatedOnDate parameter (type = datetime)
Set value of CreatedOnDate parameter to value:
="[CreatedOn].[Date].[" + Format(CDate(Parameters!CreatedOnDate.Value), "yyyy-MM-dd") + "T00:00:00]"
But when I run the report I get:
The restriction imposed by the CONSTRAINED flag in the STRTOSET function were violated
Somehow the parameter is not what you think. CONSTRAINED flag will force generating an error if the string is not a member when using StrToSet MDX function (check the failing example) :
You can try without the CONSTRAINED flag or find out the value of your parameter :
WITH
MEMBER myParam AS "[CreatedOn].[Date].[" +
Format(CDate(Parameters!CreatedOnDate.Value), "yyyy-MM-dd")
+ "T00:00:00]"
SELECT
[Measures].[myParam] on 0
FORM [Reports]
Playing a bit with this should make easier spotting the issue.
It should work if you use STRTOMEMBER for each side of the range
STRTOMEMBER("[CreatedOn].[Date].&[2010-01-01T00:00:00]", constrained):STRTOMEMBER("[CreatedOn].[Date].&[2010-02-01T00:00:00]", constrained)