Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
FredQ
Frequent Visitor

Cube.AddAndExpandDimensionColumn and New Column Name

I have tried everything I can think of and I cannot rename a column in the same line as Cube.AddAndExpandDimensionColumn.  

 

Here is the normal line without a rename:

 

{Cube.AddAndExpandDimensionColumn, "[0PROFIT_CTR__ZBBUSINES]", {"[0PROFIT_CTR__ZBBUSINES].[LEVEL01]"}, {"Business.Business Level 01"}},

 

I want to rename the column, as Microsoft tells me I can.  https://learn.microsoft.com/en-us/powerquery-m/cube-addandexpanddimensioncolumn#syntax

 

 

I try this:

 

{Cube.AddAndExpandDimensionColumn, "[0PROFIT_CTR__ZBBUSINES]", {"[0PROFIT_CTR__ZBBUSINES].[LEVEL01]"}, {"Business.Business Level 01"}, "Business"},

 

and get this error:

 

Expression.Error: 5 arguments were passed to a function which expects between 3 and 4.
Details:
Pattern=
Arguments=[List]

 

How does it get to 5 arguments?

 

I try this:

 

{Cube.AddAndExpandDimensionColumn, "[0PROFIT_CTR__ZBBUSINES]", {"[0PROFIT_CTR__ZBBUSINES].[LEVEL01]"}, {"Business.Business Level 01"}, {"Business"}},

 

and get this error:

 

Expression.Error: 5 arguments were passed to a function which expects between 3 and 4.
Details:
Pattern=
Arguments=[List]

 

I try this:

 

{Cube.AddAndExpandDimensionColumn, "[0PROFIT_CTR__ZBBUSINES]", {"[0PROFIT_CTR__ZBBUSINES].[LEVEL01]"}, {"Business.Business Level 01", "Business"}},

 

and get this error:

 

Expression.Error: We expected newColumnNames to have the same number of items as attributeNames.
Details:
[List]

 

There is only 1 column to return.  I rename 1 column.  How is that not the same number?

 

What am I doing wrong?  What is the correct syntax to accomplish this?

 

1 ACCEPTED SOLUTION
FredQ
Frequent Visitor

I figured it out!

 

I can simply rename it directly in the line by changing the last parameter:

 

Original created by the system:

 

{Cube.AddAndExpandDimensionColumn, "[0PROFIT_CTR__ZBBUSINES]", {"[0PROFIT_CTR__ZBBUSINES].[LEVEL01]"}, {"Business.Business Level 01"}},
{Table.AddColumn, "Business Code", each Cube.AttributeMemberProperty([Business.Business Level 01], "[20PROFIT_CTR__ZBBUSINES]")},

 

Original I tried this: (change in bold red)

 

{Cube.AddAndExpandDimensionColumn, "[0PROFIT_CTR__ZBBUSINES]", {"[0PROFIT_CTR__ZBBUSINES].[LEVEL01]"}, {"Business"}},
{Table.AddColumn, "Business Code", each Cube.AttributeMemberProperty([Business.Business Level 01], "[20PROFIT_CTR__ZBBUSINES]")},

 

And I got an error.  The reason is not because I cannot do it there, it was becasue I referred to the item in the next row of code and did not change it there.  This is what I needed:

 

{Cube.AddAndExpandDimensionColumn, "[0PROFIT_CTR__ZBBUSINES]", {"[0PROFIT_CTR__ZBBUSINES].[LEVEL01]"}, {"Business"}},
{Table.AddColumn, "Business Code", each Cube.AttributeMemberProperty([Business], "[20PROFIT_CTR__ZBBUSINES]")},

View solution in original post

4 REPLIES 4
FredQ
Frequent Visitor

I figured it out!

 

I can simply rename it directly in the line by changing the last parameter:

 

Original created by the system:

 

{Cube.AddAndExpandDimensionColumn, "[0PROFIT_CTR__ZBBUSINES]", {"[0PROFIT_CTR__ZBBUSINES].[LEVEL01]"}, {"Business.Business Level 01"}},
{Table.AddColumn, "Business Code", each Cube.AttributeMemberProperty([Business.Business Level 01], "[20PROFIT_CTR__ZBBUSINES]")},

 

Original I tried this: (change in bold red)

 

{Cube.AddAndExpandDimensionColumn, "[0PROFIT_CTR__ZBBUSINES]", {"[0PROFIT_CTR__ZBBUSINES].[LEVEL01]"}, {"Business"}},
{Table.AddColumn, "Business Code", each Cube.AttributeMemberProperty([Business.Business Level 01], "[20PROFIT_CTR__ZBBUSINES]")},

 

And I got an error.  The reason is not because I cannot do it there, it was becasue I referred to the item in the next row of code and did not change it there.  This is what I needed:

 

{Cube.AddAndExpandDimensionColumn, "[0PROFIT_CTR__ZBBUSINES]", {"[0PROFIT_CTR__ZBBUSINES].[LEVEL01]"}, {"Business"}},
{Table.AddColumn, "Business Code", each Cube.AttributeMemberProperty([Business], "[20PROFIT_CTR__ZBBUSINES]")},

watkinnc
Super User
Super User

Seems like you almost have it in your last line. But shouldn't the rename follow the initial pattern, like instead of

{"Business.Business Level 01", "Business"}},

 

{"Business.Business Level 01", "Business.NewColumnName"}},


What are you trying to rename the column?

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Nope, that gives the same error:

 

Expression.Error: We expected newColumnNames to have the same number of items as attributeNames.
Details:
[List]

 

With the current code, the name displayed is Business.Business Level 01.  The "." is not treated as a delimiter or anything, it is simply just text.  

 

 

FredQ
Frequent Visitor

Of course I can rename it in the next line of M Code, but Microsoft says I can do it in this same line.  

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors