cubewise-code / mdxpy Goto Github PK
View Code? Open in Web Editor NEWA simple, yet elegant MDX library for TM1
License: MIT License
A simple, yet elegant MDX library for TM1
License: MIT License
Address cubewise-code/tm1py#824 by adding a simple pyproject.toml that hands over to setup tools.
This is a sort of quick fix rather than migrating to a pure pyproject.toml approach.
mdxpy uses the OrderedSet
as a container for members in the MdxTuple
class. The added benefit is that if the same member is added multiple times to a tuple, it has no effect.
However, it comes at a cost of performance. According to my profiling analysis, on large MDX queries with (~ 500k explicit tuples) building the ordered sets takes ~50 % of the execution time.
If we replace the OrderedSet
with a simple list
, MDX construction will take roughly half the time of what it currently takes.
We are losing the comfort that Members can not be added multiple times to a MdxTuple
.
#1 this is an awesome addition to the TM1 toolkit, so thank you, I am excited to contribute.
#2 admittedly this is a bit of a blind spot for me but I wonder what is the "best" way to do attribute filtering. I have used all 3 ways in the past, but I don't know why you would use one over the others. Do you have any insight?
{FILTER({TM1SUBSETALL([Product] )}, [Product].[Product]. [Category]="Skis")}
{FILTER({TM1SUBSETALL( [Product] )}, [Product].[Product].Properties('Category')="Skis")}
{FILTER({TM1SUBSETALL([Product] )}, [Product].[}ElementAttributes_Product].([}ElementAttributes_Product].[}ElementAttributes_Product].[Category]) ="Skis")}
How to transpose rows to column in MDX .
Generate MDX output with dimension combination with measure in columns
Consider following query, returning a view, similar to a traditional "extract" view:
SELECT
{some tuple} ON ROWS
{} ON COLUMNS
FROM CUBE
Is the current master branch ready to use? Are you planning on releasing soon? I'd like to start using the MdxSet and cross join features, but figured I'd confirm that it's ready for public use first.
Trying to add an MDX tuple to an axis directly results in an exception or invalid MDX
mdx_tuple = mdxpy.MDXTuple.of(mdxpy.Member.of('Year','2019'), mdxpy.Member.of('Period','FY Total')) query.columns_non_empty().add_hierarchy_set_to_column_axis(mdx_tuple)
to_mdx:
SELECT
NON EMPTY ([YEAR].[YEAR].[2019],[PERIOD].[PERIOD].[FYTOTAL]) ON 0,
*Note the missing {} around the tuple
mdx_tuple = mdxpy.MDXTuple.of(mdxpy.Member.of('Year','2019'), mdxpy.Member.of('Period','FY Total')) query.columns_non_empty().add_member_tuple_to_columns(mdx_tuple)
AttributeError: 'MdxTuple' object has no attribute 'unique_name'
I think we need a new method to add a tuple to an axis directly.
Hello,
First of all, good job for this library, it's extremely useful ! My question might be stupid but I cannot find a way to specify multiple element within the same dimension. For example
.add_hierarchy_set_to_axis(0, MdxHierarchySet.member(Member.of("Region", "US")))
will return
{[region].[region].[us]} DIMENSION PROPERTIES MEMBER_NAME ON 0
But I want wondering how to return something like
{[region].[region].[us],[region].[region].[eu]} DIMENSION PROPERTIES MEMBER_NAME ON 0
Thank you
I have an MDX Query that I am trying to mirror,
WITH
SET [Virtual Measure:Virtual Measure:}rollup_1] AS {[Virtual Measure].[Virtual Measure].[Value]}
MEMBER [Virtual Measure].[Virtual Measure].[}rollup_1] AS AGGREGATE({[Virtual Measure:Virtual Measure:}rollup_1]})
SELECT {[Virtual Dimension].[Version].Members} ON COLUMNS ,
{[Virtual Dimension].[Measure].Members} ON ROWS
FROM [Sales Virtual]
WHERE (
[Virtual Measure].[Virtual Measure].[}rollup_1]
)
The only issue with this is I do not know of an aggregate function within MDXPy, nor do I see the capability to mirror the "SET ..." functionality on the second line of the MDX. Maybe I am just new to the library and do not see where the solution is, but I was hoping a contributor would have an idea of how to go about this.
Thanks in advance!
Could you add an MdxHierarchySet function to filter by element type using this method from Wim Gielis? Right now I'm handling using from_str.
Filter( TM1SubsetAll( [Revenue_Msr] ), [Revenue_Msr].CurrentMember.Properties("ELEMENT_TYPE")="1")
Hi is there a way to create A set of tuples for example using mdxpy:
SELECT
{([Customer].[Country].[Australia], [Product].[Product Line].[Mountain]),
([Customer].[Country].[USA], [[Product].[Product Line].[Road])}
ON 0
FROM [Adventure Works]
WHERE Measures.[Internet Sales Amount]
regards,
Ansir
Would like to request for the ability to create a MdxSet.
Which would enable to Union and Crossjoin of MdxHierarchySet.
example
{
{[VERSION].[VERSION].[ACTUAL]} * {[YEAR].[YEAR].[2021],[YEAR].[YEAR].[2022]} ,
{[VERSION].[VERSION].[BUDGET]} * {[YEAR].[YEAR].[2023]}
}
Generated MDX queries must be lower case instead of upper case due to python's habit of translating 'ร'.upper()
to SS
Hi is it possible to do crossjoin queries using this package such as:
SELECT CROSSJOIN
(
{[Customer].[Country].[Australia],[Customer].[Country].[Canada]},
{[Product].[Product Line].[Mountain],[Product].[Product Line].[Road]}
) ON 0
FROM [Adventure Works]
WHERE Measures.[Internet Sales Amount]
or
SELECT
{[Customer].[Country].[Australia],[Customer].[Country].[Canada]}*
{[Product].[Product Line].[Mountain],[Product].[Product Line].[Road]}
ON 0
FROM [Adventure Works]
WHERE Measures.[Internet Sales Amount]
so the output will be a combination of all selected dimension values.
reference to this functionally are found at the following reference to this functionally are found at the following
The DESCENDANTS function in mdxpy doesn't yet take any of the optional arguments of the DESCENDANTS MDX function.
The actual DESCENDANTS function in MDX can be parametrized as discussed in this document.
https://docs.microsoft.com/de-de/sql/mdx/descendants-mdx?view=sql-server-ver16
The additional parameters of the DESCENDANTS function need to be exposed to the descendants
function in the MdxHierarchySet
and the DescendantsHierarchySet
class needs to be modified to deal with the arguments and construct the mdx accordingly.
class DescendantsHierarchySet(MdxHierarchySet):
def __init__(self, member: Member):
super(DescendantsHierarchySet, self).__init__(member.dimension, member.hierarchy)
self.member = member
def to_mdx(self) -> str:
return f"{{DESCENDANTS({self.member.unique_name})}}"`
MDXpy should support DIMENSION PROPERTIES. They are a standard feature of MDX and are supported in TM1. Since TM1 11 they can also be used in MDX datasources for TI.
Microsoft Reference:
TM1 sample
SELECT
{[plan_time].[plan_time].[Q1-2004], [plan_time].[plan_time].[Q1-2004].CHILDREN}
DIMENSION PROPERTIES [plan_time].[Time_Swedish] on 0,
[plan_chart_of_accounts].[plan_chart_of_accounts].MEMBERS
DIMENSION PROPERTIES MEMBER_NAME on 1
FROM [plan_BudgetPlan]
WHERE ([plan_business_unit].[plan_business_unit].[10110], [plan_department].[plan_department].[105], [plan_source].[plan_source].[input])
DIMENSION PROPERTIES MEMBER_NAME, [plan_business_unit].[BusinessUnit_Swedish], [plan_business_unit].[Currency], [plan_department].[Department_Swedish]
More background in IBM Planning Analytics Forum
When using TM1py's write_values_through_cellset
function there is a noticeable difference in write speed between MDX expressions that are using the full hierarchy aware syntax and [region].[region].[ch]
the short syntax [region].[ch]
.
It would be useful if mdxpy offered a configuration to control if the short syntax is used for Members that are created without explicit Hierarchy reference.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.