Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Transform Data using M language in Power BI with TM1 POST MDX Query

Hello Eveyone, 

 

As I am new to Power BI, I dont know the possible ways of doing it. 

 

I have retrieved the Cube data from Cognos TM1 using RESTapi POST MDX query. Now I would like to do the Data Transformation, in Source I have Axes as list(has row and column name) and Cells as List(has cube values) and would like to construct a table with these. 

 

So tried using 2 queries, where one for Row and column info and other query for data like below

 

When I Append Queries, it comes with null one after the other. Merge I cant do because of no relatinship between two. I want columns in adjacent side. 

 

Any help/other approaches are highly appreciated. 

Thanks

  • Hello Anonymous 

     

    Hope i got you problem right. Check out this solution.

    let
        Source = [odata= "smetcasdcle", ID= "27cpxxx", Axes={"Axes1", "Axes2"}, Cells= {1,2}],
        CreateTable = Table.FromColumns
        (
            {
                Source[Axes],
                Source[Cells]
            },
            {"Axes", "Cells"}
        )
    in
        CreateTable

    Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy

  • Anonymous's avatar
    Anonymous
    6 years ago

    Hello Jimmy801 am very new to Power BI , 

     

    Here is the cube for testing,

     

    Here is my query:

    let
    url = "http://localhost:8000/api/v1/ExecuteMDX?$expand=Axes($select=Ordinal;$expand=Tuples($count;$expand=Members($select=Name))),Cells($select=Ordinal,Value)",

    body = "{
    ""MDX"": ""SELECT {[}zPBI_Account].[Gross], [}zPBI_Account].[Price], [}zPBI_Account].[Units]} on 0, {[}zPBI_Country].[Country01]} on 1 FROM [zPBI_SalesCube] WHERE ([}zPBI_Model].[Model1], [}zPBI_Month].[J01])""
    }",

    Source = Json.Document(Web.Contents(url, [Headers=[#"Authorization"="Basic YYY", #"Content-Type"="application/json"], Content = Text.ToBinary(body)

    ])),
    CreatedTable = Table.FromColumns({ Source[Axes], Source[Cells] }, {"Axes", "Cells"} ),

     #"Expanded Axes" = Table.ExpandRecordColumn(CreatedTable, "Axes", {"Ordinal", "[email protected]", "Tuples"}, {"Axes.Ordinal", "[email protected]", "Axes.Tuples"}),
    #"Expanded Axes.Tuples" = Table.ExpandListColumn(#"Expanded Axes", "Axes.Tuples"),
    #"Expanded Axes.Tuples1" = Table.ExpandRecordColumn(#"Expanded Axes.Tuples", "Axes.Tuples", {"Ordinal", "Members"}, {"Axes.Tuples.Ordinal", "Axes.Tuples.Members"}),
    #"Expanded Axes.Tuples.Members" = Table.ExpandListColumn(#"Expanded Axes.Tuples1", "Axes.Tuples.Members"),
    #"Expanded Axes.Tuples.Members1" = Table.ExpandRecordColumn(#"Expanded Axes.Tuples.Members", "Axes.Tuples.Members", {"Name"}, {"Axes.Tuples.Members.Name"}),
    #"Expanded Cells" = Table.ExpandRecordColumn(#"Expanded Axes.Tuples.Members1", "Cells", {"Ordinal", "Value"}, {"Cells.Ordinal", "Cells.Value"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Cells",{"Axes.Tuples.Ordinal", "Axes.Ordinal", "[email protected]", "Axes.Tuples.Members.Name", "Cells.Ordinal", "Cells.Value"}),
    #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Axes.Tuples.Ordinal", "Axes.Ordinal", "[email protected]", "Cells.Ordinal"})
    in
    #"Removed Columns"

     

    Output in PBI: 

     

    Dont know how to get the exact cube format. Even I doubted my approach will work for large cubes.:( 

     

     

     

8 Replies

  • HotChilli's avatar
    HotChilli
    Icon for Community Champion rankCommunity Champion

    If i understand you correctly, you want a new table with 2 columns.  These columns come from your 2 existing tables and you want them to merge together in the order that they they are currently in.

     

    I think you could add an index column to each table (from Add Column menu) then do a 'merge as new' with both tables (using an inner join on the Index column).

    Expand the table and remove the index columns as required.

  • Jimmy801's avatar
    Jimmy801
    Icon for Community Champion rankCommunity Champion

    Hello Anonymous 

     

    Hope i got you problem right. Check out this solution.

    let
        Source = [odata= "smetcasdcle", ID= "27cpxxx", Axes={"Axes1", "Axes2"}, Cells= {1,2}],
        CreateTable = Table.FromColumns
        (
            {
                Source[Axes],
                Source[Cells]
            },
            {"Axes", "Cells"}
        )
    in
        CreateTable

    Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello Everyone, 

       

      Thanks for your reply.  Jimmy801  yes, we both are in same page. I used your code, yes its working as expected.

       

      While coming to the real huge data for example with 5 dimesions in one cube, how to do transformation in PBI. I used Cross join in my mdx query. I would like to have 5 dimensions in table format with exact data. Is it possible? But I dont have much idea of how to transform the cube data.

       

      Any example snippet/suggestions are welcome. 

       

      I am interested in learning M language resource with example. Kindly share that too. 

       

       

      • Jimmy801's avatar
        Jimmy801
        Icon for Community Champion rankCommunity Champion

        Hello Anonymous 

         

        a MDX-statement will output always a table. So if you want to query your datamodel with MDX (I would always recomend DAX), just create your MDX statement, and the result is importet to power BI. You could use the table import assistant of Excels Power Pivot to create the code automatically. This creates a quite OKAY MDX-code by using a GUI. 

         

        Hope that helps

         

        Jimmy