This works:
=IIf(
Fields!EntityID.Value Is Nothing,
Fields!Foo.Value,
Join(
LookupSet(
Fields!EntityID.Value,
Fields!EntityID.Value,
Fields!Bar.Value,
"dsMain"
)
, ",")
)
But this doesn't:
=IIf(
Fields!EntityID.Value Is Nothing,
Fields!Foo.Value,
Count(
LookupSet(
Fields!EntityID.Value,
Fields!EntityID.Value,
Fields!Bar.Value,
"dsMain"
)
)
)
I get #Error, like if the formula is broken. What's wrong with it?
You can use the Length property of an array to get the element count
=IIf(
Fields!EntityId.Value Is Nothing,
Fields!Foo.Value,
LookupSet(
Fields!EntityId.Value,
Fields!EntityId.Value,
Fields!Bar.Value,
"dsMain"
).Length
)
Related
I am getting the error "Incorrect parameters in the call to native function 'CONCAT': on the query below:
SELECT
*,
GROUP_CONCAT(
CASE
WHEN `REASONORINSTRUCTIONCODE` = 'R'
THEN CONCAT(
"name-",
`USERWHOENTEREDTHISLINE`,
",reason-",
RTRIM(
`REASONSORSHIPPINGINSTRUCTIONS`
)
END,
", "
)
) AS reason,
GROUP_CONCAT(
CASE
WHEN [ `REASONORINSTRUCTIONCODE` ] = 'S'
THEN CONCAT(
"name-",
`USERWHOENTEREDTHISLINE`,
",shipping instruction-",
RTRIM(
`REASONSORSHIPPINGINSTRUCTIONS`
)
END,
", "
)
) AS shipping instruction
FROM
TABLE
GROUP BY `PICKUP_NO`
You have several issues with your query. First, you're not closing your CONCAT with an end ), next your AS shipping instruction cannot contain a space. Next, you have [REASONORINSTRUCTIONCODE], remove the []
Take a look at the formatted query below:
SELECT
*,
GROUP_CONCAT(
CASE
WHEN `REASONORINSTRUCTIONCODE` = 'R'
THEN CONCAT(
"name-",
`USERWHOENTEREDTHISLINE`,
",reason-",
RTRIM(
`REASONSORSHIPPINGINSTRUCTIONS`
))
END,
", "
)
AS reason,
GROUP_CONCAT(
CASE
WHEN `REASONORINSTRUCTIONCODE` = 'S'
THEN CONCAT(
"name-",
`USERWHOENTEREDTHISLINE`,
",shipping instruction-",
RTRIM(
`REASONSORSHIPPINGINSTRUCTIONS`
))
END,
", "
)
AS shipping_instruction
FROM
`TABLE`
GROUP BY `PICKUP_NO`
I am running the following command for getting a multi value report
StrToSet
("[Dim Branch].[HierarchyB-T-C].[Trading Code].&[" +
Replace(
Join(
Parameters!TradingName.Value,"],"
) +"]",",",",[Dim Branch].[HierarchyB-T-C].[Trading Code].&["),",")
But I'm getting an error
'The Syntax for 'Join' is incorrect'.
I don't know what I am doing wrong. Can anyone correct me please?
If I change it to StrToSet(#TradingName, Constrained) it works for single value, but I'd like to pass multiple values.
Do you need curly braces to form a set? I have added one at the start of the below ... a little unsure where the end of your string is - does it end like this .&["?!
StrToSet(
"{[Dim Branch].[HierarchyB-T-C].[Trading Code].&["
+
Replace(
Join(Parameters!TradingName.Value,"],") + "]"
, ","
, ",[Dim Branch].[HierarchyB-T-C].[Trading Code].&["
)
,","
)
If Parameters!TradingName.Value is equal to a string of this format MEC,RSA then maybe join is not required:
StrToSet(
"{"
+
Replace(
"[Dim Branch].[HierarchyB-T-C].[Trading Code].&["
+
Parameters!TradingName.Value
, ","
,"],[Dim Branch].[HierarchyB-T-C].[Trading Code].&["
)
+
"]}"
,constrained)
To pass multiple value from parameter, i just followed the steps
1 Add parameters and name it like
Under dataset properties (shared dataset properties as well) , the Parameters tab write an expression like this way
=Split(Parameters!TradingName.Value,",")
in Shared dataset, write the MDX with WHERE (StrToSet(#TradingName))
SELECT
{[Total]} ON COLUMNS
,
{
[Dim Account].[Account Type].&[Income]
}
*
STRTOMEMBER("[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[" + #FiscalYear +"]&[" + FORMAT(Now(),"MMMM") +"].PREVMEMBER")
*
ORDER
(
{
[Dim Branch].[Branch Name].[Branch Name]
},[Total], BDESC
)
ON ROWS
from [CubeProfitLoss]
WHERE (StrToSet(#TradingName))
when you want to preview the multiple value, make sure you are using , to separate trading name likewise
I have 1 query as given below where a parameter with name "ListOfDate" which is coming by front end in form of string..i have "ENCOUNTERDATE" in mysql with datetime datatype..
SELECT d.encounterdate,
d.hospitalid,
amiop1,
amiop2,
amiop3,
amiop4,
amiop5,
amiop16
FROM factopami f,
dimpatientencounter d
WHERE d.hospitalid = 987654
AND d.measurecategory = 'AMI'
AND ( encounterdate IN ( ** listofdate ** )
OR encounterdate IS NULL )
AND d.patientid = f.patientid
AND d.id = f.patientencounterid
ORDER BY encounterdate;
after it i tried to convert ListOfDate into date:
SELECT d.encounterdate, d.hospitalid, amiop1, amiop2, amiop3, amiop4,
amiop5, amiop16
FROM factopami f, dimpatientencounter d
WHERE d.hospitalid = 987654
AND d.measurecategory = 'AMI'
AND ( encounterdate IN (str_to_date ('01-10-2012' '%m-%d-%Y'))
OR encounterdate IS NULL
)
AND d.patientid = f.patientid
AND d.ID = f.patientencounterid
ORDER BY encounterdate;
which is working for single string ...but i got list of string which is giving me error..
SELECT d.encounterdate,
d.hospitalid,
amiop1,
amiop2,
amiop3,
amiop4,
amiop5,
amiop16
FROM factopami f,
dimpatientencounter d
WHERE d.hospitalid = 987654
AND d.measurecategory = 'AMI'
AND ( encounterdate IN ( Str_to_date('01-10-2012', '01-10-2012',
'%m-%d-%Y') )
OR encounterdate IS NULL )
AND d.patientid = f.patientid
AND d.id = f.patientencounterid
ORDER BY encounterdate;
LIMIT 0, 1000 Error Code: 1582. Incorrect parameter count in the call to native function 'STR_TO_DATE' 0.000 sec
so how can i convert it to on mysql level
In short - at the moment you're converting the list to:
(encounterdate IN ( STR_TO_DATE('01-10-2012','01-10-2012', '%m-%d-%Y'))
Instead, you need to convert it to:
( encounterdate IN ( STR_TO_DATE('01-10-2012', '%m-%d-%Y')
, STR_TO_DATE('01-10-2012', '%m-%d-%Y') )
As more of an explanation, the IN operator is expecting a list of things:
encounterdate IN ( thing1, thing2, thing3 )
The thing you are passing is a date, meaning you're doing this:
encounterdate IN ( date1, date2, date3 )
Alas, you have strings instead of dates, and so you need to convert each of those strings into dates. Thus you need to some conversions.
date1 needs to be STR_TO_DATE( string1, '%m-%d-%y )
date2 needs to be STR_TO_DATE( string2, '%m-%d-%y )
date3 needs to be STR_TO_DATE( string3, '%m-%d-%y )
Putting that all together, you need to generate:
encounterdate IN ( STR_TO_DATE('01-10-2012', '%m-%d-%Y')
, STR_TO_DATE('01-10-2012', '%m-%d-%Y')
, STR_TO_DATE('01-10-2012', '%m-%d-%Y')
As an alternative, if you feel it's not possible to produce this, you could flip the conversion round and instead convert the encounterdate column to a string using DATE_FORMAT as you do the comparison.
Documentation here:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format
http://www.w3schools.com/sql/func_date_format.asp
This would result in:
DATE_FORMAT( encounterdate, '%m-%d-%Y' ) IN ( '01-10-2012'
, '01-10-2012'
, '01-10-2012' )
However, you should bear in mind that this will have an impact on the indexing of encounterdate, though this might not be a problem in your use-case.
As it is explained in mysql manual, str_to_date function , get only to parameters. The first parameter is your date string, and the second one is the format of your date string.so you cann't use it like this:
STR_TO_DATE('01-10-2012','01-10-2012', '%m-%d-%Y')
You should use this:
STR_TO_DATE('01-10-2012', '%m-%d-%Y'),STR_TO_DATE('01-10-2012', '%m-%d-%Y')
I am using a pivot query in SQL as below:
SELECT classification, [BSL] AS BSL, [AQ] AS AQ, [KYN] AS KYN, ([BSL] + [AQ] +
[KYN]) AS CR_TTL
FROM
(
SELECT classification, Shed
FROM PunctualityMain WHERE Date >= '4/1/2012' AND Date <= '6/30/2012'
) x
PIVOT
(
COUNT(Shed)
FOR Shed IN ([BSL], [AQ], [KYN])) p ">
In result i am getting 0 in null cells, is it possible to show null in place of 0 in result page?
the simplest solution would be to use the NULLIF shortcut, like so:
SELECT classification
, NULLIF([BSL],0) AS BSL
, NULLIF([AQ],0) AS AQ
, NULLIF([KYN],0) AS KYN
, NULLIF([BSL] + [AQ] + [KYN],0) AS CR_TTL
FROM
(
SELECT classification, Shed
FROM PunctualityMain WHERE Date >= '4/1/2012' AND Date <= '6/30/2012'
) x
PIVOT
(
COUNT(Shed)
FOR Shed IN ([BSL], [AQ], [KYN])) p
How to pass MultiSelect parameter from SSRS to MDX?
I tried as below which is not working as expected:
WHERE ({IIF( STRTOSET(#Name, CONSTRAINED).Count = 1,
STRTOSET(#Name, CONSTRAINED), [Name].currentmember )})
You can use directly :
WHERE ( STRTOSET(#Name, CONSTRAINED) )
or (not sure about this ) :
WHERE ( IIF( STRTOSET(#Name, CONSTRAINED).Count = 1,
STRTOSET(#Name, CONSTRAINED),
STRTOMEMBER(#Name, CONSTRAINED) ) )
However SSAS and set slicers are not always good friends. If possible use MDX Subselects instead :
WHERE ( SELECT STRTOSET(#Name, CONSTRAINED) ON 0 FROM .. )