For example...........
Database Table:
BatchID BatchName Chemical Value
--------------------------------------------------------
BI-1 BN-1 CH-1 1
BI-2 BN-2 CH-2 2
--------------------------------------------------------
I need to display following cube
BI-1 BI-2
BN-1 BN-2
-----------------------------------------
CH-1 1 null
------------------------------------------
CH-2 null 2
------------------------------------------
Here BI-1,BN-1 are two rows in a single columns i need to display chemical value as row of that.
What is query MDX query for this.
Could Please help me to solve this problem.
Thank You.
Create a cube with BatchID, Batchname and Chemical as dimensions and Value as measure.
Then use the following MDX code:
SELECT
Crossjoin(Crossjoin([BatchID].Members, [Batchname].Members), { [Measures].[Value] }) ON COLUMNS,
[Chemical].Members ON ROWS
FROM [Mycube]
Related
I have a PIVOT query that is returning an unknown number of dynamic columns. So the query will return something like
ID | Col1 | Col2 | ..... | ColN
ID is the only static column and the rest are all dynamic. The number and the names of the columns are unknown.
How can I write a report in SSRS that can handle this? Any tips and direction will be appreciated.
Thanks.
SSRS will not be able to handle your pivot table because the columns are not known at design time. SSRS has feature called Matrix that will handle the pivot a run time based off run time data if your design time structure is static.
ID | ColumnName | Value
------------------------
1 | Colu1 | Value1
1 | Colu2 | Value2
2 | Colu2 | Value2
I would recommend that you return detail rows from TSQL and allow SSRS to handle the pivot. This will allow for one stored procedure to be used for multiple SSRS reports and aggregations instead of the single aggregation provide by PIVOT.
To save on duplicate processing, Matrix will also handle the sorting so no need to sort inside of TSQL.
Reference: Create a Matrix
I have a table A within a dataset in Bigquery. This table has multiple columns and one of the columns called hits_eventInfo_eventLabel has values like below:
{ID:AEEMEO,Score:8.990000;ID:SEAMCV,Score:8.990000;ID:HBLION;Property
ID:DNSEAWH,Score:0.391670;ID:CP1853;ID:HI2367;ID:H25600;}
If you write this string out in a tabular form, it contains the following data:
**ID | Score**
AEEMEO | 8.990000
SEAMCV | 8.990000
HBLION | -
DNSEAWH | 0.391670
CP1853 | -
HI2367 | -
H25600 | -
Some IDs have scores, some don't. I have multiple records with similar strings populated under the column hits_eventInfo_eventLabel within the table.
My question is how can I parse this string successfully WITHIN BIGQUERY so that I can get a list of property ids and their respective recommendation scores (if existing)? I would like to have the order in which the IDs appear in the string to be preserved after parsing this data.
Would really appreciate any info on this. Thanks in advance!
I would use combination of SPLIT to separate into different rows and REGEXP_EXTRACT to separate into different columns, i.e.
select
regexp_extract(x, r'ID:([^,]*)') as id,
regexp_extract(x, r'Score:([\d\.]*)') score from (
select split(x, ';') x from (
select 'ID:AEEMEO,Score:8.990000;ID:SEAMCV,Score:8.990000;ID:HBLION;Property ID:DNSEAWH,Score:0.391670;ID:CP1853;ID:HI2367;ID:H25600;' as x))
It produces the following result:
Row id score
1 AEEMEO 8.990000
2 SEAMCV 8.990000
3 HBLION null
4 DNSEAWH 0.391670
5 CP1853 null
6 HI2367 null
7 H25600 null
You can write your own JavaScript functions in BigQuery to get exactly what you want now: http://googledevelopers.blogspot.com/2015/08/breaking-sql-barrier-google-bigquery.html
I'm trying to solve this query where i need to find the the top balance at each base. Balance is in one table and bases are in another table.
This is the existing query i have that returns all the results but i need to find a way to limit it to 1 top result per baseID.
SELECT o.names.name t.accounts.bidd.baseID, MAX(t.accounts.balance)
FROM order o, table(c.accounts) t
WHERE t.accounts.acctype = 'verified'
GROUP BY o.names.name, t.accounts.bidd.baseID;
accounts is a nested table.
this is the output
Name accounts.BIDD.baseID MAX(T.accounts.BALANCE)
--------------- ------------------------- ---------------------------
Jerard 010 1251.21
john 012 3122.2
susan 012 3022.2
fin 012 3022.2
dan 010 1751.21
What i want the result to display is calculate the highest balance for each baseID and only display one record for that baseID.
So the output would look only display john for baseID 012 because he has the highest.
Any pointers in the right direction would be fantastic.
I think the problem is cause of the "Name" column. since you have three names mapped to one base id(12), it is considering all three records as unique ones and grouping them individually and not together.
Try to ignore the "Name" column in select query and in the "Group-by" clause.
SELECT t.accounts.bidd.baseID, MAX(t.accounts.balance)
FROM order o, table(c.accounts) t
WHERE t.accounts.acctype = 'verified'
GROUP BY t.accounts.bidd.baseID;
How can I get the MDX query below to display the date next to the customer? Currently it only displays the customer, or whichever dimension I make first in the nonempty call. I'd like both to show in the results.
SELECT {[Measures].[Count1], [Measures].[Count2],
[Measures].[Count3]} ON COLUMNS,
nonempty({[Customers]}, {[DateRange]}) ON Rows
FROM Cube
I tried crossjoin but that return an out of memory error.
Thanks!
I am getting this:
Customer | Count1 | Count2 | Count3 |
I would like to see this:
Customer | Date | Count1 | Count2 | Count3 |
Generally a measure goes as the second argument of NONEMPTY
SELECT {[Measures].[Count1], [Measures].[Count2],
[Measures].[Count3]} ON COLUMNS,
nonempty(({[Customers]}, {[DateRange]}),{[Measures].[Count1], [Measures].[Count2],
[Measures].[Count3]}) ON Rows
FROM Cube
I put all three measures as part of the set for the NonEmpty function. This would return data where any row has at least one of the three counts that isn't null. It only filters out rows that are null for all three counts.
I have the following star schema:
Objects <-> Facts <-> Simulation
-ObjectID -ObjectID -SimulationID
-SimulationID -SimulationID
-ObjHierarchy -Volume
-ObjectType
Now I'm trying to filter the cube using both dimensions:
select [Measures].[Volume] on columns,
[Objects].[ObjHierarchy].[Level 02] on rows
from [DM OC]
where ([Objects].[ObjectType].&[2], [Simulation].[SimulationID].&[52])
However, this returns rows for SimulationID=52 (with values) but also duplicates for SimulationID=53 (with nulls):
ObjHierarchy | Volume
MyObj1 | 12345
MyObj2 | 54321
MyObj1 | (NULL)
MyObj2 | (NULL)
A workaround is to use NonEmpty, however it just seems the cube isn't modeled the right way.
It is a usual case and doesn't mean that the cube's model wrong.
In MDX, you should also filter the rows by using any filter function if you don't want them to appear in your result. In your case, you should use NonEmtpy to eleminate the empty values.
Can you execute the following :
with member XX as [Objects].[ObjHierarchy].currentMember.Properties( "KEY" )
select { [Measures].[Volume], XX } on columns,
[Objects].[ObjHierarchy].[Level 02] on rows
from [DM OC]
where ([Objects].[ObjectType].&[2], [Simulation].[SimulationID].&[52])
MyObj1 and MyObj2 should not have the same key; otherwise I do not see right now.