MDX query for filter

EP_explorer
Regular Participant
Posts: 202
Joined: Sat Dec 04, 2010 2:35 pm
OLAP Product: PAL
Version: 2.0.9
Excel Version: 2016

MDX query for filter

Post by EP_explorer »

I want to write MDX query which will be filter values in the 1st Cube based on the values in the 2nd Cube.

There are 2 conditions -
1) if value in the second Cube is empty it shows all detail elements of dimension.
2) And if value in the second Cube is not empty it uses this value for filtering.

I wrote query for the second case - look the code but I don't know how to connect with the first one

Code: Select all

{FILTER(
{TM1FILTERBYLEVEL( {TM1SUBSETALL( [dim_for_filter] )}, 0)}, 
[Cube1].([dim1].CurrentMember,
[dim2].CurrentMember,
[dim3].[Region]) = 
[Cube2].([dim11].[Name], [dim12].[Region]) )}
rmackenzie
MVP
Posts: 733
Joined: Wed May 14, 2008 11:06 pm

Re: MDX query for filter

Post by rmackenzie »

The requirement seems really complex... can we ask the what practical purpose is?

Looking at your query, it seems odd that you reference .CurrentMember twice for different dimensions implying that an element in dim_for_filter would correspond to a similarly named element in dim1 and dim2. Is this the case? E.g. do you have an element 'X' in 3 different dimensions - this would be unusual, I think. Also, dim1 and dim2 are both in at least 2 cubes per your example. Obviously, this isn't unusual in itself, but it would be useful to know what sort of string data you envision both cubes containing.

This document has lots of useful information including how to filter a dimension on the value in a cube, which is half of what you want.
Robin Mackenzie
EP_explorer
Regular Participant
Posts: 202
Joined: Sat Dec 04, 2010 2:35 pm
OLAP Product: PAL
Version: 2.0.9
Excel Version: 2016

Re: MDX query for filter

Post by EP_explorer »

rmackenzie wrote:The requirement seems really complex... can we ask the what practical purpose is?

Looking at your query, it seems odd that you reference .CurrentMember twice for different dimensions implying that an element in dim_for_filter would correspond to a similarly named element in dim1 and dim2. Is this the case? E.g. do you have an element 'X' in 3 different dimensions - this would be unusual, I think. Also, dim1 and dim2 are both in at least 2 cubes per your example. Obviously, this isn't unusual in itself, but it would be useful to know what sort of string data you envision both cubes containing.

This document has lots of useful information including how to filter a dimension on the value in a cube, which is half of what you want.
That document I read of course

I put a sceen from Excel that I want to see
07.JPG
07.JPG (45.99 KiB) Viewed 14992 times
rmackenzie
MVP
Posts: 733
Joined: Wed May 14, 2008 11:06 pm

Re: MDX query for filter

Post by rmackenzie »

I appreciate you uploading the screenshot... but still, it is very difficult to understand the problem you are having and what you are trying to achieve in a practical sense. Can you elaborate?
Robin Mackenzie
EP_explorer
Regular Participant
Posts: 202
Joined: Sat Dec 04, 2010 2:35 pm
OLAP Product: PAL
Version: 2.0.9
Excel Version: 2016

Re: MDX query for filter

Post by EP_explorer »

I want to give opportunity for users to filter data in Cube1 (based on MDX expression in one of its dimensions) using parameters in Cube2.
AmbPin
Regular Participant
Posts: 173
Joined: Sat Mar 20, 2010 3:03 pm
OLAP Product: TM1
Version: 9.5.2
Excel Version: 2007-10

Re: MDX query for filter

Post by AmbPin »

Hello,

If I understand what you are trying to do correctly then I think something like this should set you on the right track:-

Code: Select all

TM1FilterByPattern( 
	{
		TM1FILTERBYLEVEL( 
			{TM1SUBSETALL( [dim_for_filter] )}, 0
		)
	}
	, [Cube2].([dim2-1].[el2-1], [dim2-2].[el2-2]...)
)							
EP_explorer
Regular Participant
Posts: 202
Joined: Sat Dec 04, 2010 2:35 pm
OLAP Product: PAL
Version: 2.0.9
Excel Version: 2016

Re: MDX query for filter

Post by EP_explorer »

I don't think it will help.

after
TM1FILTERBYLEVEL(
{TM1SUBSETALL( [dim_for_filter] )}, 0
)

we will recieve
1, 2, 3, 4, 5, 6 etc.

And when we try TM1FilterByPattern used data in [Cube2].([dim2-1].[el2-1], [dim2-2].[el2-2]
Region 1 for example to (1, 2, 3, 4, 5)

we will recieve nothing
Alas.
AmbPin
Regular Participant
Posts: 173
Joined: Sat Mar 20, 2010 3:03 pm
OLAP Product: TM1
Version: 9.5.2
Excel Version: 2007-10

Re: MDX query for filter

Post by AmbPin »

I am sorry, I dont really understand what you are trying to achieve in that case, can you re-phrase your question?
rmackenzie
MVP
Posts: 733
Joined: Wed May 14, 2008 11:06 pm

Re: MDX query for filter

Post by rmackenzie »

EP_explorer wrote:I want to write MDX query which will be filter values in the 1st Cube based on the values in the 2nd Cube.
EP_explorer, I've gone back to your original point - and on re-reading it - it seems that you want to filter data in cube 1 based on values in cube 2. This implies that cube 2 holds values that correspond to element names in a dimension in cube 1. E.g. I can enter 'Region1' somewhere in cube 2, and then we see that element 'Region1' in the subset of a dimension that exists in cube 1, subsequently filtering data in the cube view.

The bihints link, and example provided by AmbPin, are reasonable examples of how to achieve that. It's not clear to people why you can't use that approach which is well understood. Please can you explain in terms specific to your cube, why that approach doesn't work for you?

Perhaps you are saying that you want to filter values in a dimension of cube 1, so that the value selected is the same as a cell value in cube 2 which also matches a cell value in cube 3? This is different and a lot more complex. Is that your problem?
Robin Mackenzie
EP_explorer
Regular Participant
Posts: 202
Joined: Sat Dec 04, 2010 2:35 pm
OLAP Product: PAL
Version: 2.0.9
Excel Version: 2016

Re: MDX query for filter

Post by EP_explorer »

I have Cube with some dimensions one of them (dim_for_filter) contains elements:
1, 2, 3, 4, 5, 6 ....
Region
1 Region1
2 Region1
3 Region2
4 Region3
5 Region1
6 Region2

I want to filter data in this Cube (choose some elements from dim_for_filter) if data from one of elements in measure dimension (Region) is the same as choosing in Cube 2 (cube for choosing Regions)

So if User choose Region1 in Cube2
he will recieve in Cube 1
Region
1 Region1
2 Region1
5 Region1

But if user doesn't choose anything in Cube 2 he will receive full list of elements
Region
1 Region1
2 Region1
3 Region2
4 Region3
5 Region1
6 Region2

I want to do it using MDX expression to dimension dim_for_filter
EP_explorer
Regular Participant
Posts: 202
Joined: Sat Dec 04, 2010 2:35 pm
OLAP Product: PAL
Version: 2.0.9
Excel Version: 2016

Re: MDX query for filter

Post by EP_explorer »

rmackenzie wrote:
EP_explorer wrote:I want to write MDX query which will be filter values in the 1st Cube based on the values in the 2nd Cube.
EP_explorer, I've gone back to your original point - and on re-reading it - it seems that you want to filter data in cube 1 based on values in cube 2. This implies that cube 2 holds values that correspond to element names in a dimension in cube 1. E.g. I can enter 'Region1' somewhere in cube 2, and then we see that element 'Region1' in the subset of a dimension that exists in cube 1, subsequently filtering data in the cube view.

The bihints link, and example provided by AmbPin, are reasonable examples of how to achieve that. It's not clear to people why you can't use that approach which is well understood. Please can you explain in terms specific to your cube, why that approach doesn't work for you?
AmbPin decison isn't correct and I explained why
rmackenzie wrote: Perhaps you are saying that you want to filter values in a dimension of cube 1, so that the value selected is the same as a cell value in cube 2 which also matches a cell value in cube 3? This is different and a lot more complex. Is that your problem?
Yes you are almost right. But not "also matches a cell value in cube 3"
but "also matches a cell value in cube 1"

It could be done with function Filter which I put in the first post but I don't know how to join it if the value in Cube 2 is empty. Function Filter based on empty value will return no elements from dim_for_filter
rmackenzie
MVP
Posts: 733
Joined: Wed May 14, 2008 11:06 pm

Re: MDX query for filter

Post by rmackenzie »

EP_explorer wrote:There are 2 conditions -
1) if value in the second Cube is empty it shows all detail elements of dimension.
2) And if value in the second Cube is not empty it uses this value for filtering.
EP_explorer wrote:I don't know how to join it if the value in Cube 2 is empty. Function Filter based on empty value will return no elements from dim_for_filter
So you are questioning why condition (1) doesn't return what you want?

Based on my understanding of the documentation, conditional logic per the Microsoft standard isn't supported in the TM1 implementation.
Robin Mackenzie
AmbPin
Regular Participant
Posts: 173
Joined: Sat Mar 20, 2010 3:03 pm
OLAP Product: TM1
Version: 9.5.2
Excel Version: 2007-10

Re: MDX query for filter

Post by AmbPin »

There are 2 conditions -
1) if value in the second Cube is empty it shows all detail elements of dimension.
2) And if value in the second Cube is not empty it uses this value for filtering.
If instead of empty you put "*" in the second cube, I believe my suggestion would work.
EP_explorer
Regular Participant
Posts: 202
Joined: Sat Dec 04, 2010 2:35 pm
OLAP Product: PAL
Version: 2.0.9
Excel Version: 2016

Re: MDX query for filter

Post by EP_explorer »

rmackenzie wrote:
EP_explorer wrote:There are 2 conditions -
1) if value in the second Cube is empty it shows all detail elements of dimension.
2) And if value in the second Cube is not empty it uses this value for filtering.
EP_explorer wrote:I don't know how to join it if the value in Cube 2 is empty. Function Filter based on empty value will return no elements from dim_for_filter
So you are questioning why condition (1) doesn't return what you want?

Based on my understanding of the documentation, conditional logic per the Microsoft standard isn't supported in the TM1 implementation.
I noticed the fact that TM-1 doesn't support function IIF

So I ask how I could do that I want using other ways.
EP_explorer
Regular Participant
Posts: 202
Joined: Sat Dec 04, 2010 2:35 pm
OLAP Product: PAL
Version: 2.0.9
Excel Version: 2016

Re: MDX query for filter

Post by EP_explorer »

AmbPin wrote:
There are 2 conditions -
1) if value in the second Cube is empty it shows all detail elements of dimension.
2) And if value in the second Cube is not empty it uses this value for filtering.
If instead of empty you put "*" in the second cube, I believe my suggestion would work.
Alas
Function Filter with "*" doesn't work - return empty selection
Apparently it is trying to find string "*" but not any elements as in FilterbyPattern
AmbPin
Regular Participant
Posts: 173
Joined: Sat Mar 20, 2010 3:03 pm
OLAP Product: TM1
Version: 9.5.2
Excel Version: 2007-10

Re: MDX query for filter

Post by AmbPin »

To demonstrate my suggestion I have set up a simple parameter/control cube.
Capture01.PNG
Capture01.PNG (3.88 KiB) Viewed 14849 times
I will use this to filter values in a simple time dimension "Time Monthly"

Derived from the code sample I posted earlier:-

Code: Select all

TM1FilterByPattern( 
	{
		TM1FILTERBYLEVEL( 
			{TM1SUBSETALL( [Time Monthly] )}, 0
		)
	}
	, [System Information].([System Information Measures].[FilterVal], [System Information Values].[Value])
) 
I get (not surprisingly) a single result "Apr_2013".
If I then put "*" in the parameter/control cube:-
Capture02.PNG
Capture02.PNG (3.15 KiB) Viewed 14849 times
And use the above MDX to filer my time dimension again, I get all of the zero level elements.

As I understand your question, this would seem to cover it.
EP_explorer
Regular Participant
Posts: 202
Joined: Sat Dec 04, 2010 2:35 pm
OLAP Product: PAL
Version: 2.0.9
Excel Version: 2016

Re: MDX query for filter

Post by EP_explorer »

I will be :evil: :evil: :evil: :evil: soon
;)

Dimension which you have to filter ([Time Monthly]) by FilterbyPattern doesn't contain months
You have to choose element in Cube2 and using it trying to filter data in Cube1 but not in dimension as you are doing!!

If it were so simple as in your example I wouldn't ask it here.

Please - see all my examples attentively
lotsaram
MVP
Posts: 3654
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: MDX query for filter

Post by lotsaram »

EP_explorer wrote:I will be :evil: :evil: :evil: :evil: soon
;)

Dimension which you have to filter ([Time Monthly]) by FilterbyPattern doesn't contain months
You have to choose element in Cube2 and using it trying to filter data in Cube1 but not in dimension as you are doing!!

If it were so simple as in your example I wouldn't ask it here.

Please - see all my examples attentively
It seems to me that AmbPin and Robin have tried to assist, AND moreover it seems to me that they as opposed to you have done the work in trying to elaborate on clarifying the problem. So if other people's interpretation of the issue isn't correct and you are serious about needing assistance then you need to do some work in explaining more detail exactly what the technical problem is, not others need to work harder to understand your description of the problem. If you want assistance that's the wrong way to go about it.

Even better yet explain not just the technical issue but the business requirement in detail too as there may be an easier way coming from the business requirement as opposed to just the technical side.
Last edited by lotsaram on Mon Apr 29, 2013 1:54 pm, edited 1 time in total.
tomok
MVP
Posts: 2832
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: MDX query for filter

Post by tomok »

Your examples, combined with the explanations, don't make any sense. That's why you aren't getting what you want. Based on my review of the examples, it looks like you want to filter items in a dimension called "Dim_For_Filter", which contains elements 1,2,3,4,5,etc., based on a string cell in Cube2, which will either contain the name of an element in the Region dimension, or be blank. The end result of that filtering looks to be showing only those regions that match the string in Cube2, or if blank, all the regions. Why in the world are you wasting your time trying to create a filter in the Dim_For_Filter dimension????? Just filter the MDX subset in the Region dimension, using the examples given. That will give you want you want. If you zero-suppress the view, only the Dim_For_Filter elements that have data in the selected region will show up. This is the ONLY way your scheme is going to work.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
AmbPin
Regular Participant
Posts: 173
Joined: Sat Mar 20, 2010 3:03 pm
OLAP Product: TM1
Version: 9.5.2
Excel Version: 2007-10

Re: MDX query for filter

Post by AmbPin »

Please - see all my examples attentively
As others have said, I think you need to be more attentive with your question. Everyone else here seems to know how to do this and is trying to help.
Post Reply