cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Pateen Frequent Visitor
Frequent Visitor

Renamed fields in Query Editor causes error in Reports

Hi there,

 

I've a a large number of reports running off a dataset connecting to directly to SQL Server.  I've had to rename several fields to more useful names in the Query ediitor.

 

When I refresh these reports I get the following error below.

 

Is there a way of renaming fields so my reports will pick up these newly named fields dynamically?

 

 

rename.JPG

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Renamed fields in Query Editor causes error in Reports

Few ways to go about this.  Since it's coming from sql I think it would be safe to assume that the order of the columns would be the same.  Going with that idea:

 

  • Create a List of desired column names in the order of the current output from sql
  • New Column Name List.png
  • to translate that table into a list you can use:
  • = Table.ToList(Source)
  • Then can add this function into a blank query:
(Source as table, Index as list, NewNames as list) =>
let
    #"Index of Old Columns" =
	List.Transform(Index, each Table.ColumnNames( Source ){_}

),
    ZippedList = List.Zip( {#"Index of Old Columns",NewNames}),
    #"Rename Columns" = Table.RenameColumns(Source, ZippedList)
in
    #"Rename Columns"

Then you can use that function in your table:

= fnRenameColumns(Source, {0..(List.Count(NewColumnNames)-1)},NewColumnNames)

Could use a few more steps to get rid of that List.Count, but this works just fine. 

Before and After.png

 

Credit to Gil Raviv and his amazing book on Power Query!

View solution in original post

2 REPLIES 2
Super User
Super User

Re: Renamed fields in Query Editor causes error in Reports

Few ways to go about this.  Since it's coming from sql I think it would be safe to assume that the order of the columns would be the same.  Going with that idea:

 

  • Create a List of desired column names in the order of the current output from sql
  • New Column Name List.png
  • to translate that table into a list you can use:
  • = Table.ToList(Source)
  • Then can add this function into a blank query:
(Source as table, Index as list, NewNames as list) =>
let
    #"Index of Old Columns" =
	List.Transform(Index, each Table.ColumnNames( Source ){_}

),
    ZippedList = List.Zip( {#"Index of Old Columns",NewNames}),
    #"Rename Columns" = Table.RenameColumns(Source, ZippedList)
in
    #"Rename Columns"

Then you can use that function in your table:

= fnRenameColumns(Source, {0..(List.Count(NewColumnNames)-1)},NewColumnNames)

Could use a few more steps to get rid of that List.Count, but this works just fine. 

Before and After.png

 

Credit to Gil Raviv and his amazing book on Power Query!

View solution in original post

Community Support Team
Community Support Team

Re: Renamed fields in Query Editor causes error in Reports

Hi @Pateen ,

Have you solved your problem?

If you have solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

If you still need help, please feel free to ask.

Best Regards,

Cherry

 

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

New Badges

Incoming: New and Improved Badges

Exciting news: We've given our badges an overhaul and added brand news ones.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Top Kudoed Authors
Users Online
Currently online: 297 members 3,115 guests
Please welcome our newest community members: