MDX for current and previous month

Post Reply
M1ndbender
Posts: 39
Joined: Mon Jul 19, 2021 2:15 pm
OLAP Product: TM1
Version: 2.0.0
Excel Version: 365
Location: Canada

MDX for current and previous month

Post by M1ndbender »

Hi All,
I have a period dimension that is by day. days roll up to months, months to quarters and quarters to years.
I am trying to create dynamic mdx that will return the current month and previous month

This works to return the current month

Code: Select all

FILTER(TM1SUBSETALL([report_HDD_fiscalPeriodByDay]) , [report_HDD_fiscalPeriodByDay].CURRENTMEMBER.NAME = [CONTROL].([Control Parameters].[Current Month],[CONTROL_m].[S-Value]))
And this works for previous month if I hard code CURRENTMEMBER.NAME to the current month

Code: Select all

FILTER(TM1SUBSETALL([report_HDD_fiscalPeriodByDay]) , [report_HDD_fiscalPeriodByDay].CURRENTMEMBER.NAME = [report_HDD_fiscalPeriodByDay].CURRENTMEMBER.PROPERTIES("PreviousPeriod"))
Is there a way to combine these so it will bring back current and previous at the same time?
MarenC
Regular Participant
Posts: 455
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Re: MDX for current and previous month

Post by MarenC »

Hi,

either of these should work, but there are lots of different ways:

Code: Select all

FILTER(TM1SUBSETALL([report_HDD_fiscalPeriodByDay]) , [report_HDD_fiscalPeriodByDay].CURRENTMEMBER.NAME = [CONTROL].([Control Parameters].[Current Month],[CONTROL_m].[S-Value])) + FILTER(TM1SUBSETALL([report_HDD_fiscalPeriodByDay]) , [report_HDD_fiscalPeriodByDay].CURRENTMEMBER.NAME = [report_HDD_fiscalPeriodByDay].CURRENTMEMBER.PROPERTIES("PreviousPeriod"))

Code: Select all

FILTER(TM1SUBSETALL([report_HDD_fiscalPeriodByDay]) , [report_HDD_fiscalPeriodByDay].CURRENTMEMBER.NAME = [CONTROL].([Control Parameters].[Current Month],[CONTROL_m].[S-Value]) or [report_HDD_fiscalPeriodByDay].CURRENTMEMBER.NAME = [report_HDD_fiscalPeriodByDay].CURRENTMEMBER.PROPERTIES("PreviousPeriod"))
Maren
User avatar
gtonkin
MVP
Posts: 1274
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: MDX for current and previous month

Post by gtonkin »

How about using StrToMember to derive the members based on the text in the control cube or attribute?
You can then just separate each derived member with a comma and enclose in braces to return both in a set.

Code: Select all

{	
StrToMember("[report_HDD_fiscalPeriodByDay].[" + 
[CONTROL].([Control Parameters].[Current Month],[CONTROL_m].[S-Value] + "]"),

StrToMember("[report_HDD_fiscalPeriodByDay].[" + 
	StrToMember("[report_HDD_fiscalPeriodByDay].[" + 
	  [CONTROL].([Control Parameters].[Current Month],[CONTROL_m].[S-Value] + 
	  "]").PROPERTIES("PreviousPeriod") + "]")	
}
BR, George.

Learn something new: MDX Views
M1ndbender
Posts: 39
Joined: Mon Jul 19, 2021 2:15 pm
OLAP Product: TM1
Version: 2.0.0
Excel Version: 365
Location: Canada

Re: MDX for current and previous month

Post by M1ndbender »

That seems to have worked perfectly. Thank you so much for your help.
User avatar
gtonkin
MVP
Posts: 1274
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: MDX for current and previous month

Post by gtonkin »

Pleasure - glad it worked!
BR, George.

Learn something new: MDX Views
Post Reply