Does the following select statement exclude the mentioned CustomerIDs - reporting-services

I want to find out if my rdl report excludes the CustomerIDs "1001", "FF" and "99998002", I don't know where and how it is defined in the report builder, but I can see the source code of the .rdl file has this select statement:
SELECT NON EMPTY {
[Measures]...
}
ON COLUMNS, NON EMPTY {
(
...
)
}
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_VALUE, MEMBER_UNIQUE_NAME ON ROWS FROM
( SELECT ( -{ [Customer].[CustomerID].&[1001], [Customer].[CustomerID].&[99998002], [Customer].[CustomerID].&[FF] }
...
Which I think means it is excluding the CustomerIds, but I couldn't find any description of the syntax: " SELECT ( -{" online

The minus sign is shorthand for the keyword EXCEPT.

Related

Add JSON_OBJECT to one of multiple arrays

I have several tables whose records have a type identifier. For example a table AUTOS has a MANUFACTURER field. I'd like to be able to create an json_object for each row and add that object to a manufacturer specific array, e.g.
{
fordCars: [],
chevyCars: []
}
The arrays are members of a parent object (let's name it #parent)
As I indicated I have several such tables that should be treated the same way.
I thought I might define a variable
DECLARE #mfgs json;
initialize it as follows:
SET #mfgs = '{
"fordCars": [],
"chevyCars": []
}';
I thought I could populate the arrays as follows but the arrays in #mfg are empty:
SELECT CASE
WHEN MANUFACTURER='FORD' THEN SELECT JSON_ARRAY_APPEND(#mfgs, '$.fordCars', JSON_OBJECT(
'MANUFACTURER',d.MANUFACTURER,
'MAKE',d.MAKE,
'MODEL',d.MODEL
))
WHEN MANUFACTURER='CHEVY' THEN SELECT JSON_ARRAY_APPEND(#mfgs, '$.chevyCars', JSON_OBJECT(
'MANUFACTURER',d.MANUFACTURER,
'MAKE',d.MAKE,
'MODEL',d.MODEL
))
END
from AUTOS d
I would then:
JSON_MERGE_PRESERVE(#parent, #mfgs)
The above does not work and in any case requires that I repeat all json/sql mappings for each case statement.
Does anyone know how I can accumulate json_objects in one of multiple arrays based on the value, in this case of MANUFACTURER?
Installation is mySQL 8.023.
Thanks in advance.
An answer that eliminates the issue of having to repeat each of the AUTOS table fields for each grouping of MANUFACTURER. I am still unable however to use JSON_* functions to provide arguments to JSON_MERGE_PRESERVE.
IF someone knows how to accomplish this it would make for a more elegant solution imho.
SET json_auto_detail = (select JSON_MERGE_PRESERVE(json_auto_detail,
(select concat('{', GROUP_CONCAT(jsonString SEPARATOR "," ),'}') from (
SELECT concat('"', mfgArrayName, '":', mfgArrayObj) as 'jsonString' from (
(select
if (MANUFACTURER='FORD', 'fordCars',
if (MANUFACTURER='Chevy', 'chevyCars')) as 'mfgArrayName',
json_arrayagg(JSON_OBJECT(
'make', MANUFACTURER,
'model', MODEL,
'id', ID
)) as 'mfgArrayObj'
from AUTOS
where MANUFACTURER in ('FORD', 'CHEVY')
group by MANUFACTURER
)
) as autos -- up to 2 rows of auto json objects
) as mAutos))
); -- autos merged with json_auto_detail

Putting a working union query into a subquery causes JOIN syntax error

When I try to run the following query in Access 2016, I get a "Syntax error in JOIN operation" message.
Tables in use:
VISIB_BOMS is basically a self referencing hierarchy of part numbers in a Bill of Materials. (Similar to the classic example of an employee table where the employee can manager other employees.)
ztbl_IFSParts is just 1 column table of part numbers that I want to get the sub-component part numbers for.
The end goal is to have a single column table of all component parts from the parts from ztbl_IFSParts. I'll then use this list to get further info from JOINs to other tables.
SELECT *
FROM
(
/* CODE BETWEEN HERE WORKS */
(
SELECT DISTINCT aa0.PartNo AS PartNo
FROM ztbl_IFSParts AS aa0
)
UNION ALL
(
SELECT DISTINCT b0.COMPPARTNO AS PartNo
FROM
(
SELECT DISTINCT aa0.PartNo AS PartNo
FROM ztbl_IFSParts AS aa0
) AS ab0
LEFT JOIN VISIB_BOMS AS b0
ON ab0.PartNo = b0.ASSYPARTNO
)
/* CODE BETWEEN HERE WORKS */
)
If I run the code between the comments on its own it works fine, only when I try to do any SELECT operations on it, it throws an error.
Hope it's enough info to run with.
Removing the brackets around the two queries either side of the UNION ALL solved this.

MDX filter level member

My question is how to filter valid field by another field in MDX.
I have one table: samples;
if I use sql to solve problem , just like this:
select patient_id from samples where calc_test_type_id = 1;
I created dimension for this: Patient Characteristic
Hierarchy: id
level : id (patient id in samples table) , including property, named 'testA', 'testA' linked to calc_test_type_id.
So I tried MDX like this :
SELECT
{[Measures].[num_samples]} ON COLUMNS,
{
filter
(
distinct([Patient characteristic.id].[id].members),
[Patient characteristic.id].CurrentMember.Properties("calc_type") = 1
)
} ON ROWS
FROM [EIDCube]
[Measures].[num_samples] is to calculate how many rows for calc_test_type_id = 1.
But I found some data lost. So how to find all suitable patient id ?
Your code looks fine. Try creating the set first. Also I don't think you need distinct:
WITH SET [calc_type1] AS
FILTER
(
[Patient characteristic.id].[id].members)
,[Patient characteristic.id].CurrentMember.Properties("calc_type") = 1
)
SELECT
{[Measures].[num_samples]} ON 0,
[calc_type1] ON 1
FROM [EIDCube];
To check the set returned I'd be tempted to run this script without that measure first, like this:
WITH SET [calc_type1] AS
FILTER
(
[Patient characteristic.id].[id].members)
,[Patient characteristic.id].CurrentMember.Properties("calc_type") = 1
)
SELECT
{} ON 0,
[calc_type1] ON 1
FROM [EIDCube];

MDX: How to get dimension count

I execute this query and gives me this error:
Infinite Recursion Detected: The loop of dependencies is: Direct Reporting->Direct Reporting.
Can anybody help me?
WITH
MEMBER [Measures].[Direct Reporting] AS COUNT([Employee].[Employees].Members, EXCLUDEEMPTY)
SELECT
{[Measures].[Direct Reporting]} ON COLUMNS,
{[Geography].[Country].AllMembers} ON ROWS
FROM [Adventure Works]
You've picked a special type of hierarchy: a parent/child hierarchy.
Here is an example of a count against the advWks cube:
WITH
MEMBER [Measures].[aCount] AS
Sum
(
(
[Customer].[Customer].[Customer]
,[Customer].[Customer Geography].CurrentMember
)
,IIF
(
[Measures].[Internet Order Quantity] > 50
,1
,0
)
)
SELECT
{
[Measures].[Direct Reporting]
,[Measures].[Internet Order Count]
} ON COLUMNS
,{[Customer].[Customer Geography].[Country].MEMBERS} ON ROWS
FROM [Adventure Works];
Specifying Count with EXCLUDEEMPTY means the engine needs to evaluate the cube's cells referenced by each member of the dimension and the current [Measures]. Not 100% sure about SSAS behavior but it seems the current [Measures] is the calc. measure being defined itself: hence the infinite loop.
To fix it, you can explicitly define the [Measures]:
WITH MEMBER [Measures].[Direct Reporting] AS
COUNT( { [Measures].[use-here-your-measure] } * [Employee].[Employees].Members, EXCLUDEEMPTY)
Or perhaps use the NonEmpty function:
AS Count( NonEmpty( [Employee].[Employees].Members,
[Measures].[use-here-your-measure] ))
Hope that helps.

How To Filter a list in String with MDX

Goal:
Filter the value in the table column based on string "Canada" as a criteria.
Problem:
I cannot get the MDX syntax code in where state to be correct in order to filter the data based on Canada.
Information:
This situation is a simplified sample and my request is to add filter criteria in the where state.
Data source is SSAS:s AdventureWorksDW2012
Code:
SELECT
{
[Measures].[Reseller Order Count],
[Measures].[Discount Amount]
} ON COLUMNS,
{
([Reseller].[Reseller Type].[Business Type].ALLMEMBERS )
} ON ROWS
FROM [Adventure Works]
WHERE
(
FILTER
(
[Geography].[Country].ALLMEMBERS, [Geography].[Country].NAME ='Canada'
)
)
There are two issues:
In Adventure Works, the Geography dimension is not linked to the Internet Sales measure group. Have a look at the cube definition, tab "Dimension Usage". You should use the hierarchies from the Customer dimension found in the Location folder when using measures from the Internet Sales measure group. I use [Customer].[Country] below.
In a filter, you should use Current and a set alias to refer to the current element during the iteration of the set.
The following shows what you want, I just changed the Filter:
SELECT
{
[Measures].[Reseller Order Count],
[Measures].[Discount Amount]
} ON COLUMNS,
{
([Reseller].[Reseller Type].[Business Type].ALLMEMBERS )
} ON ROWS
FROM [Adventure Works]
WHERE
(
FILTER
(
[Customer].[Country].ALLMEMBERS as c, c.current.NAME ='Canada'
)
)