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.
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?
Solved! Go to Solution.
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]")},
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]")},
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
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.
Of course I can rename it in the next line of M Code, but Microsoft says I can do it in this same line.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.