Let's say I have the following MDX Query:
Select
{measures.[Dollars]} on 0,
non empty
[Divisions].[Division].[All].Children *
[Cost Centres].[Cost Centre].[All].Children
[Locations].[Locations].[All].Children
on 1
From MyCube
which produced the following table:
<table><tbody><tr><th>Division</th><th> Cost Centre</th><th> Location</th><th> Dollars</th></tr><tr><td>AA</td><td>1</td><td>X</td><td>$30.00 </td></tr><tr><td>AA</td><td>1</td><td>X</td><td>$12.32 </td></tr><tr><td>AA</td><td>1</td><td>X</td><td>$124.32 </td></tr><tr><td>AA</td><td>1</td><td>Z</td><td>$64.24 </td></tr><tr><td>BB</td><td>1</td><td>Z</td><td>$63.13 </td></tr><tr><td>BB</td><td>1</td><td>Z</td><td>$84.23 </td></tr><tr><td>BB</td><td>2</td><td>Z</td><td>$254.37 </td></tr><tr><td>BB</td><td>2</td><td>Y</td><td>$27.23 </td></tr><tr><td>CC</td><td>2</td><td>Z</td><td>$12.01 </td></tr><tr><td>CC</td><td>2</td><td>Y</td><td>$12.42 </td></tr><tr><td>CC</td><td>2</td><td>Y</td><td>$53.26 </td></tr><tr><td>CC</td><td>1</td><td>Y</td><td>$76.26 </td></tr><tr><td>CC</td><td>1</td><td>Z</td><td>$63.74 </td></tr><tr><td>CC</td><td>1</td><td>Z</td><td>$2.74 </td></tr></tbody></table>
What I am hoping to do is create a set out of the Union of specific values in the [Cost Centres].[Cost Centre] and [Locations].[Locations] hierarchies into a single set and use that new set in my MDX query across the columns.
Using the table and query from above, I have the following conditions that would determine the value in the set (lets call the new set 'NewSet'):
When Cost Centre = 1 and Location = X Then "CustomType1"
When Cost Centre = 1 and Location = Y Then "CustomType2"
When Cost Centre = 1 and Location = Z Then "CustomType3"
When Cost Centre = 2 and Location = Y Then "CustomType4"
When Cost Centre = 2 and Location = Z Then "CustomType5"
Else "Default"
Then, if I was to execute the new query:
with
set NewSet as "Some Unknown Magic Here"
Select {measures.[Dollars]} on 0,
non empty
[Divisions].[Division].[All].Children *
{NewSet}
on 1
From MyCube
I would end up with the following result:
<table><tbody><tr><th>Division</th><th> NewSet</th><th>Dollars</th></tr><tr><td>AA</td><td>CustomType1 </td><td>$166.64 </td></tr><tr><td>AA</td><td>CustomType3 </td><td>$64.24 </td></tr><tr><td>BB</td><td>CustomType3 </td><td>$147.36 </td></tr><tr><td>BB</td><td>CustomType4</td><td>$27.23 </td></tr><tr><td>BB</td><td>CustomType5</td><td>$254.37 </td></tr><tr><td>CC</td><td>CustomType2</td><td>$76.26 </td></tr><tr><td>CC</td><td>CustomType3</td><td>$66.48 </td></tr><tr><td>CC</td><td>CustomType4</td><td>$65.68 </td></tr><tr><td>CC</td><td>CustomType5</td><td>$12.01 </td></tr></tbody></table>
You just have a set of tuples of the members from each hierarchy that you're interested in:
SELECT
{measures.[Dollars]} ON 0
,NON EMPTY
[Divisions].[Division].[All].Children*
{
([Cost Centres].[Cost Centre].[1], [Locations].[Locations].[x]),
([Cost Centres].[Cost Centre].[1], [Locations].[Locations].[y]),
([Cost Centres].[Cost Centre].[1], [Locations].[Locations].[z]),
([Cost Centres].[Cost Centre].[2], [Locations].[Locations].[y]),
([Cost Centres].[Cost Centre].[2], [Locations].[Locations].[z])
}
ON 1
FROM MyCube;
Or this can go in the WITH clause as in your question:
WITH SET [BLAH] AS
{
([Cost Centres].[Cost Centre].[1], [Locations].[Locations].[x]),
([Cost Centres].[Cost Centre].[1], [Locations].[Locations].[y]),
([Cost Centres].[Cost Centre].[1], [Locations].[Locations].[z]),
([Cost Centres].[Cost Centre].[2], [Locations].[Locations].[y]),
([Cost Centres].[Cost Centre].[2], [Locations].[Locations].[z])
}
SELECT
{measures.[Dollars]} ON 0
,NON EMPTY
[Divisions].[Division].[All].Children*
[BLAH]
ON 1
FROM MyCube;
Related
Why does this code show invalid identifier when sum is used in distance and air_time column?
When sum is not used this statement process successfully but using sum I get error? I need to use sum for this statement.
MERGE INTO FACT_COMPANY_GROWTH F
USING (SELECT DISTINCT TIME_ID, FLIGHT_KEY, AEROPLANE_KEY, SUM(DISTANCE) AS TOTAL_DISTANCE, SUM(AIR_TIME) AS TOTAL_AIRTIME
FROM TRANSFORM_FLIGHT T
INNER JOIN TRANSFORM_AEROPLANE A
ON T.FK_AEROPLANE_KEY = A.AEROPLANE_KEY
INNER JOIN DIM_TIME D
ON D.YEAR = T.YEAR
AND D.MONTH = T.MONTH
GROUP BY TIME_ID, FLIGHT_KEY, AEROPLANE_KEY) S
ON (F.FK1_TIME_ID = S.TIME_ID
AND F.FK2_FLIGHT_KEY = S.FLIGHT_KEY
AND F.FK3_AEROPLANE_KEY = S.AEROPLANE_KEY
)
WHEN MATCHED THEN
UPDATE SET
F.TOTAL_AIRTIME = S.AIR_TIME,
F.TOTAL_DISTANCE = S.DISTANCE,
F.TOTAL_NO_OF_FLIGHTS = S.FLIGHT_KEY,
F.TOTAL_NO_OF_AEROPLANE = S.AEROPLANE_KEY
WHEN NOT MATCHED THEN
INSERT(FACT_ID, FK1_TIME_ID, FK2_FLIGHT_KEY, FK3_AEROPLANE_KEY, TOTAL_DISTANCE, TOTAL_AIRTIME, TOTAL_NO_OF_FLIGHTS, TOTAL_NO_OF_AEROPLANE)
VALUES
(NULL, S.TIME_ID, S.FLIGHT_KEY, S.AEROPLANE_KEY, S.DISTANCE, S.AIR_TIME, S.FLIGHT_KEY, S.AEROPLANE_KEY);
USING(
SELECT DISTINCT
TIME_ID,
FLIGHT_KEY,
AEROPLANE_KEY,
SUM(DISTANCE) AS TOTAL_DISTANCE,
SUM(AIR_TIME) AS TOTAL_AIRTIME
...) S
The problem is at UPDATE SET F.TOTAL_AIRTIME = S.AIR_TIME. There are 5 fields defined in S and none is named AIR_TIME.
UPDATE SET
F.TOTAL_AIRTIME = S.TOTAL_AIRTIME,
F.TOTAL_DISTANCE = S.TOTAL_DISTANCE,
I have written the below piece of code to pick a row from web table to process it. The code picks/opens the first row successfully, however, when it is trying to double click the second row, it errors out with an error "Unspecified error". The web table has 7 rows, nevertheless, it is failing. Can some one point out what could be the reason for the failure please?
Set objDesc = Description.Create
objDesc("micclass").Value = "WebTable"
objDesc("html tag").Value = "Table"
Set objList = Browser("3 - Employee Assign Benefits").Page("3 - Employee Assign Benefits").Frame("APPFRAMEWORK").ChildObjects(objDesc)
oCount = objList.Count
For k =0 To oCount - 1
colName = objList(k).GetRoproperty("cols")
If Trim(colName) = 21 Then 'This is the right table
objList(k).Highlight
rows= objList(k).GetROProperty("rows")
For i = 1 To rows
x = objList(k).ChildItem(i,1,"WebElement",0).GetROProperty("abs_x")
y = objList(k).ChildItem(i,1,"WebElement",0).GetROProperty("abs_y")
Wait(2)
Set obj = CreateObject("Mercury.DeviceReplay")
obj.MouseDblClick x,y,LEFT_MOUSE_BUTTON
Call ClickVerifyElement(Browser("3 - Employee Assign Benefits").Page("3 - Employee Assign Benefits").Frame("APPFRAMEWORK").WebEdit("ben_elig_dte"), "ben_elig_dte", "WebEdit", Parameter("elig_date"))
Call ClickVerifyElement(Browser("3 - Employee Assign Benefits").Page("3 - Employee Assign Benefits").Frame("APPFRAMEWORK").WebList("emp_state_withd_opt_decode"), "emp_state_withd_opt_decode", "WebList", Parameter("withhold_ind"))
Browser("3 - Employee Assign Benefits").Page("3 - Employee Assign Benefits").Frame("APPFRAMEWORK").WebButton("Save").Click
Next
Exit For
End If
Next
SELECT DISTINCT dha.order_number,
dha.ordered_date,
dha.org_id,
houf.name Business_Unit,
dha.TRANSACTIONAL_CURRENCY_CODE,
dla.ORDERED_QTY,
dla.UNIT_SELLING_PRICE,
esib.item_number,
esit.description,
hca.account_name,
hzps.PARTY_SITE_NAME,
cicev.UNIT_COST_AVERAGE,
MAX (cicev.cost_date) AS MaxDate
FROM DOO_HEADERS_ALL dha,
DOO_PRICE_ADJUSTMENTS dpa,
hr_organization_units_f_tl houf,
DOO_LINES_ALL dla,
DOO_FULFILL_LINES_ALL dfla,
egp_system_items_b esib,
egp_system_items_tl esit,
hz_cust_accounts hca,
HZ_party_sites hzps,
CST_ITEM_COST_ELEMENTS_V cicev
WHERE dha.org_id = houf.organization_id
AND dha.header_id = dla.header_id
AND esib.inventory_item_id = dfla.inventory_item_id
AND dfla.inventory_item_id = esit.INVENTORY_ITEM_ID
AND dfla.header_id = dha.header_id
AND dha.SOLD_TO_PARTY_ID = hca.party_id
AND dha.SOLD_TO_PARTY_ID = hzps.party_id
AND esit.inventory_item_id = cicev.inventory_item_id
GROUP BY (dha.order_number)
All columns that aren't aggregated must be included into the GROUP BY clause, which means that it should look like this; note that column aliases must be removed!
GROUP BY dha.order_number,
dha.ordered_date,
dha.org_id,
houf.name,
dha.TRANSACTIONAL_CURRENCY_CODE,
dla.ORDERED_QTY,
dla.UNIT_SELLING_PRICE,
esib.item_number,
esit.description,
hca.account_name,
hzps.PARTY_SITE_NAME,
cicev.UNIT_COST_AVERAGE
Apart from that, there's no need for DISTINCT (in SELECT) because GROUP BY will select distinct values anyway.
[EDIT: how to include a new condition into the WHERE clause?]
select ...
from ...
where cicev.cost_date = (select max(cicev1.cost_date)
from CST_ITEM_COST_ELEMENTS_V cicev1
where cicev1.inventory_item_id = cicev.inventory_item_id
)
and ...
I'm using PL/SQL and I get the "Not all variables are bound" when I execute the sql expression. I'm selecting data by passing values into 3 parameters. Therefore "host variables" do not help me in here.
SELECT SomeApi1_Api.Get_Part_No(t.or_no, t.l_no, t.rel_no, t.item_no),
t.description,
c.serial_no,
c.lot_batch_no,
t.order_no,
t.line_no,
t.release_no,
SomeApi1_Api.Get_State(t.or_no, t.l_no, t.rel_no, t.item_no)
FROM TableView1 c,
TableView2 t
WHERE c.or_no = t.or_no
AND c.l_no = t.l_no
AND c.rel_no = t.rel_no
AND c.item_no = t.item_no
AND deliv_no IN (SELECT deliv_no
FROM TableView3 a
WHERE a.del_no IN (SELECT DISTINCT dele_no
FROM TableView3 cod,
TableView4 cdi
WHERE cod.deliv_no = cdi.deliv_no
AND cdi.i_id = t.i_id
AND cdi.item_id = t.item_id
AND cdi.co = t.co
AND a.or_no = t.or_no
AND a.l_no = l_no
AND a.rel_no = rel_no
AND a.item_no = item_no))
AND t.i_id = '&A'
AND t.item_id = '&B'
AND t.co = '&C'
I have an Excel sheet which has 200 columns. Now number of rows are 3500. So i have to search a string if it presents within any column for each row. Now to make the process fatser,I am looking for any alternate instead of Looping technique. Is there any such?
IntRow6 = 2
DataCount = 0
Do While objSheet6.Cells(IntRow6,1).Value <> ""
For DataCount = 0 to UBound(VMHArray)
IntClmn3 = 1
Do While 1 = 1
If objSheet6.Cells(IntRow6,IntClmn3).Value = VMHArray(DataCount) Then
objSheet6.Cells(IntRow6,IntClmn3+2).Value=objSheet6.Cells(IntRow6,IntClmn3+5).Value
Exit Do
End If
IntClmn3 = IntClmn3 + 1
Loop
Next
IntRow6 = IntRow6 + 1
Loop
The above is taking to much time, thus i am looking for an equivalent VBScript code which can run more faster search.
EDIT:
ParentColmnCount=ParentColmnCount-1
IntRow6=2
DataCount=0
Do While objSheet6.Cells(IntRow6,1).Value <> ""
For DataCount=0 to UBound(VMHArray)
If objSheet6.Range(objSheet6.Cells(IntRow6,1),objSheet6.Cells(IntRow6,ParentColmnCount)).Find(VMHArray(DataCount)) <> Nothing Then
MsgBox("Hi")
End If
Next
IntRow6=IntRow6+1
Loop
I'm getting any error saying that, "Object variable not set" error at the Range line of the above code.
UPDATE
I have updated my code as per your suggestion,and modified the declaration of variables as below:
Option Explicit
Dim objExcel1,objWorkbook
Dim strPathExcel1
Dim objSheet6,objSheet3
Dim IntRow6,IntRow3
Dim IntClmn3
Dim DataCount,ParentColmnCount
Dim Falg
Dim TaskCounter
Dim r As Range
Dim s As Variant
But I am getting the error again: Expected end of statement" in the line "Dim r As Range"
Check out Range.Find (which returns a Range object). It's faster than a loop.
Example:
Sub Test()
Dim r As Range
Dim matched As Range
'Get the second row
Set r = Sheet1.Range("2:2")
Set matched = r.Find("myString")
'Do stuff with matched
End Sub
UDPATE:
Assuming you are using CreateObject("Excel.Application"), then the Range object will be present (as CreateObject will return an instance of Excel which contains Range objects and functionality).
For further proof, you're already looping through the worksheet using Range objects (Cells is a Range object).
UPDATE:
Here's a more advanced example. Assume the following data in on Sheet1:
fred ethel ricky bobby 1 2 3 4
lucy myrtle fonzy rickie 1 2 3 4
joanie chachie donna patty 1 2 3 4
selma homer lisa bart 1 2 3 4
You can loop through the ranges like so:
Sub test()
Dim r As Range
Dim names(3) As String
Dim s As Variant
names(0) = "ethel"
names(1) = "fonzy"
names(2) = "patty"
names(3) = "selma"
For Each s In names
For Each r In Sheet1.Cells.CurrentRegion.Find(s)
r.Offset(0, 4).Value = r.Offset(0, 4).Value + 1000
Next r
Next s
End Sub
After the routine is done, the data is now:
fred ethel ricky bobby 1 1002 3 4
lucy myrtle fonzy rickie 1 2 1003 4
joanie chachie donna patty 1 2 3 1004
selma homer lisa bart 1001 2 3 4
UPDATE:
I just saw your comment on your question (and edited your question to include the updated code).
You're getting "Object variable not set" on that line because you cannot use <> comparisons with objects. Change the line to read:
If Not objSheet6.Range(objSheet6.Cells(IntRow6,1),objSheet6.Cells(IntRow6,ParentColmnCount)).Find(VMHArray(DataCount)) Is Nothing Then