How to do a MDX Except crossjoin dimension query - ssas

Consider the following data. I would like to get the NON{Country:USA & Gender:F} using MDX
- - - - - - - - - - - - - - - - - - - - -
| Country | Gender | Sales |
- - - - - - - - - - - - - - - - - - - - -
USA M 1000
USA F 500
Spain M 200
Spain F 600
What I want to extract would be:
- - - - - - - - - - - - - - - - - - - - -
| Country | Gender | Sales |
- - - - - - - - - - - - - - - - - - - - -
USA M 1000
Spain M 200
Spain F 600
I tried to use crossjoin, union and except to do that, e.g.
WITH SET [Test] AS
[Country].[CountryCode].[USA] * Except ([Gender].members,{[Gender].[GenderCode].[F]}) +
Except([Country].[CountryCode].members, {[Country].[CountryCode].[USA]}) * [Gender].members
SELECT
NON EMPTY [Test] ON ROWS,
{[Measures].[Sales]} ON COLUMNS
FROM [SalesCube]
It works, but may i know if there is any other simpler way to do it ?
Thanks.

If you want to exclude few combinations, you can use Except on the cross join with the excepted combinations as tuples like this:
WITH SET [Test] AS
Except(CrossJoin([Country].[CountryCode].members,
[Gender].members
),
{ ([Country].[CountryCode].[USA], [Gender].[GenderCode].[F]) }
)
...
And syntactically, you an abbreviate CrossJoin as * and Except as -, as well as Union as +, which have the usual rules of precedence (* has higher precendece than - and +):
WITH SET [Test] AS
[Country].[CountryCode].members * [Gender].[GenderCode].members
-
{ ([Country].[CountryCode].[USA], [Gender].[GenderCode].[F]) }
...

Related

How to get Nth string after a pipe delimiter in hive

I have some a table in Hive where in I want to extract 5th component of the string from one of the columns that looks like this -
Sample data
john:12|doe|google|usa|google.com|newspaper - title - 1 - volume - 1234|360671191
john:34|doe|fb|usa|google.com|newspaper - title - X - volume - 1233|360671192
john:45|doe|twitter|usa|google.com|newspaper - title - Y - volume - 1232|360671193
jane:45:1323
I would like to parse out 5th string after the first pipe character(|). The output column would have value as -
newspaper - title - 1 - volume - 1234
newspaper - title - X - volume - 1233
newspaper - title - Y - volume - 1232
jane:45:1323
In case the title is not present (like in record 4) , then we return the original string as is.
Use split function, like this:
with your_data as (
select stack(4,
'john:12|doe|google|usa|google.com|newspaper - title - 1 - volume - 1234|360671191',
'john:34|doe|fb|usa|google.com|newspaper - title - X - volume - 1233|360671192',
'john:45|doe|twitter|usa|google.com|newspaper - title - Y - volume - 1232|360671193',
'jane:45:1323'
) as str
)
select nvl(splitted_str[5], original_str) result
from
(
select split(str,'\\|') splitted_str, str original_str
from your_data
)s;
Returns:
newspaper - title - 1 - volume - 1234
newspaper - title - X - volume - 1233
newspaper - title - Y - volume - 1232
jane:45:1323

VB.NET How to get the last value from a Column in a DataTable

I have a DataTable called DTPerson like this:
Name - - - - - Age - - - - - Number
John - - - - - 16 - - - - - 1234567
Mike - - - - - 25 - - - - - 1231231
I need to retrieve the last field from the Column "Name" in DTPerson.
I want label1.text = Mike
I've looked everywhere and could only find examples for Datasets so I'm not sure what to do.
Try This.
DTPerson.Rows(DTPerson.Rows.Count -1).Item("Name").ToString()

"current month" and "cumulative monthly expenditure" data within the same query [duplicate]

I've posted a couple of question on this site regarding this topic and I thank you for your input. I decided to take a step back and see if I can rephrase my question a bit better.
The below code provides a Running sum across various product numbers. Unfortunately, it provides a running total regardless of the Product number. That said, I need the running total to be calculated based on the product number. See below example code and current/desired output.
Note that the month field was left out, this is a test database that I created to see if some sample code that I found would work. Now I want to see if I can take it a bit further to provide the below desired output.
Example Code:
SELECT Prod.Product, Prod.Amount, DSum("[Amount]","[Prod]","[Amount] >=" & [Amount]) AS RunTot, Prod.EndDate
FROM Prod
GROUP BY Prod.Product, Prod.Amount, Prod.EndDate;
Desired Output - Example:
Product - SumOfAmount -RunTot - month
7000XZ - $600.00 - 600 - 10/28/14
7000XZ - $500.00 - $1100 - 11/28/14
7000YT - $400.00 - $400 - 10/28/14
7000YT - $300.00 - $700 - 11/28/14
7000AB - $200.00 - $200 - 10/28/14
7000AB - $100.00 - $300- 11/28/14
7000WE - $130.00 - $130 - 10/28/14
7000WE - $121.00 - $251 - 11/28/14
Current OutPut - Example:
7000XZ - $600.00 - $600
7000XZ - $500.00 - $1100
7000YT - $400.00 - $1500
7000YT - $300.00 - $1800
7000AB - $200.00 - $2000
7000WE - $130.00 - $2130
7000WE - $121.00 - $2251
7000AB - $100.00 - $2351
Current output Report:
I played around with the input provided and didn't get the desired input. Please take a look.
![Sample Report After flowing instruction at:
https://support.office.com/en-us/article/Summing-in-reports-ad4e310d-64e9-4699-8d33-b8ae9639fbf4?CTT=1&CorrelationId=4c1bcd05-6bab-4844-8d51-47111c6ab911&ui=en-US&rs=en-US&ad=US#bmrunningsum]1

How can I split a column based on similer values of column in SQL

I have a table in which 3 columns studentid, qualification and board.
It show like
Studentid - qualification - board
1 - highschool - cbse
1 - intermidiate - cbse
2 - highschool - up board
2 - intermidiate - up board
I need a query that give result like.
studentid - qualification-1 - qualification-2 - board-1 - board-2
1 - highschool - intermidiate - cbse - cbse
2 - highschool - intermidiate - up board - up board
Can any one solve it?
SELECT studentid, qualification AS 'qualification-1', qualification AS 'qualification-2', board AS 'board-1', board AS 'board-2' WHERE 1 GROUP BY studentid
Use AS to create alias of field

Replacing info in Access

I have a table within Access that looks similar to this:
ProductID - ClientID - ProductName - Description
118 - 5 - Full Search - xxxx
35 - 2 - Update - xxxx
105 - 7 - O & E - xxxx
I want to be able to call the ProductID and have it return the ProductName field.
ProductID = Forms!Orders.Product.Value()
Any help?
You can use DLookUp:
DlookUp("ProductName","Products","ProductID=" & SomeNumericID)
There are other ways, but you need to say where you are coming from and going to.