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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
KunalMathkar
Frequent Visitor

I need support for write or rectify query

I have connected power bi with clickhouse database.

my table name is  "jira_issues"

i have explained query below

 

KunalMathkar_0-1748514404759.png

i have pasted this in chatgpt and i got elow response as query -

let
Source = jira_issues,

// Define your custom field mappings here
CustomFieldMap = [
"customfield_10000" = "Development",
"customfield_10103" = "Original story points",
// Add more mappings as needed
],

// Get all column names
ColumnNames = Table.ColumnNames(Source),

// Generate new column names based on mapping
RenamedColumnsList = List.Transform(ColumnNames, (colName) =>
let
// Try to find a matching customfield key in the column name
matchingKey = List.First(List.Select(Record.FieldNames(CustomFieldMap), each Text.StartsWith(colName, _)), null),
newName = if matchingKey <> null then
Text.Replace(colName, matchingKey, Record.Field(CustomFieldMap, matchingKey))
else
colName
in
{colName, newName}
),

// Apply renaming
RenamedTable = Table.RenameColumns(Source, RenamedColumnsList)
in
RenamedTable

 

 

 

after writing this qury in transform query editor in power bi i am getting below error but you can see that value is present in column name.

KunalMathkar_0-1748514100834.png

images for reference - 

KunalMathkar_1-1748514176325.png

 

help me to resolve this so i can rename all column names using query.if above query is wrong let me know right query

 

1 ACCEPTED SOLUTION
KunalMathkar
Frequent Visitor

yes i got ny correct query and query is here

 

let
    // Connect to the ClickHouse database
    Source = ClickHouse.Database("10.1.1.1", 1, null, []),
 
    // Navigate to the specific database and table
    DB = Source{[Name = "abc", Kind = "Database"]}[Data],
    JiraIssues = DB{[Name = "jira", Kind = "Table"]}[Data],
 
    // Define the mapping of custom field names to friendly names
    CustomFieldMap = [
        customfield_10000 = "Request participants",
        customfield_10103 = "Account"
 
        // Add more mappings here, separated by commas
    ],
 
    // Get all column names from the table
    ColumnNames = Table.ColumnNames(JiraIssues),
 
    // Generate a list of {oldName, newName} pairs based on the mapping
    RenamedColumnsList = List.Transform(ColumnNames, (colName) =>
        let
            matchingKey = List.First(List.Select(Record.FieldNames(CustomFieldMap), each Text.StartsWith(colName, _)), null),
            newName = if matchingKey <> null then
                        Text.Replace(colName, matchingKey, Record.Field(CustomFieldMap, matchingKey))
                      else
                        colName
        in
            {colName, newName}
    ),
 
    // Apply the renaming to the table
    RenamedTable = Table.RenameColumns(JiraIssues, RenamedColumnsList)
in
    RenamedTable

View solution in original post

9 REPLIES 9
KunalMathkar
Frequent Visitor

yes i got ny correct query and query is here

 

let
    // Connect to the ClickHouse database
    Source = ClickHouse.Database("10.1.1.1", 1, null, []),
 
    // Navigate to the specific database and table
    DB = Source{[Name = "abc", Kind = "Database"]}[Data],
    JiraIssues = DB{[Name = "jira", Kind = "Table"]}[Data],
 
    // Define the mapping of custom field names to friendly names
    CustomFieldMap = [
        customfield_10000 = "Request participants",
        customfield_10103 = "Account"
 
        // Add more mappings here, separated by commas
    ],
 
    // Get all column names from the table
    ColumnNames = Table.ColumnNames(JiraIssues),
 
    // Generate a list of {oldName, newName} pairs based on the mapping
    RenamedColumnsList = List.Transform(ColumnNames, (colName) =>
        let
            matchingKey = List.First(List.Select(Record.FieldNames(CustomFieldMap), each Text.StartsWith(colName, _)), null),
            newName = if matchingKey <> null then
                        Text.Replace(colName, matchingKey, Record.Field(CustomFieldMap, matchingKey))
                      else
                        colName
        in
            {colName, newName}
    ),
 
    // Apply the renaming to the table
    RenamedTable = Table.RenameColumns(JiraIssues, RenamedColumnsList)
in
    RenamedTable
v-dineshya
Community Support
Community Support

Hi @KunalMathkar ,

Thank you for reaching out to the Microsoft Community Forum.

 

Please refer the M code.

let
Source = jira_issues,

CustomFieldMap = [
"customfield_10000" = "Development",
"customfield_10103" = "Rank"
],

ColumnNames = Table.ColumnNames(Source),

RenamedColumnsList = List.Transform(ColumnNames, (colName) =>
let
matchingKey = List.First(List.Select(Record.FieldNames(CustomFieldMap), each Text.Contains(colName, _)), null),
newName = if matchingKey <> null then
Text.Replace(colName, matchingKey, Record.Field(CustomFieldMap, matchingKey))
else
colName
in
{colName, newName}
),

RenamedTable = Table.RenameColumns(Source, RenamedColumnsList)
in
RenamedTable

Tested the M code with sample code.

1. Created sample data, refer the snap.

vdineshya_0-1748616000327.png

2.  Created M code for sample code.

let

Source = #table(
{"customfield_10000", "customfield_10103_category", "customfield_10103_category_key", "subtask_keys", "customfield_engagement"},
{
{"dev_1", "A", "A1", "STK1", "ENG1"},
{"dev_2", "B", "B2", "STK2", "ENG2"}
}
),

CustomFieldMap = Record.FromList(
{"Development", "Rank"},
{"customfield_10000", "customfield_10103"}
),

ColumnNames = Table.ColumnNames(Source),

RenamedColumnsList = List.Transform(ColumnNames, (colName) =>
let
matchingKey = List.First(List.Select(Record.FieldNames(CustomFieldMap), each Text.Contains(colName, _)), null),
newName = if matchingKey <> null then
Text.Replace(colName, matchingKey, Record.Field(CustomFieldMap, matchingKey))
else
colName
in
{colName, newName}
),

RenamedTable = Table.RenameColumns(Source, RenamedColumnsList)
in
RenamedTable

Sample code output.

vdineshya_1-1748616135324.png

Please refer output snap and PBIX file.

 

If my response has resolved your query, please mark it as the "Accepted Solution" to assist others. Additionally, a "Kudos" would be appreciated if you found my response helpful.

Thank you

Hi @KunalMathkar ,

We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet.do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

 

Thank you.

Hi @KunalMathkar ,

We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet.do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

 

Thank you.

KunalMathkar
Frequent Visitor

let
Source = jira_issues,

// Define your custom field mappings here
CustomFieldMap = [
customfield_10000 = "Development",
customfield_10103 = "Original story points"
// Add more mappings as needed
],

// Get all column names
ColumnNames = Table.ColumnNames(Source),

// Generate new column names based on mapping
RenamedColumnsList = List.Transform(ColumnNames, (colName) =>
let
// Try to find a matching customfield key in the column name
matchingKey = List.First(List.Select(Record.FieldNames(CustomFieldMap), each Text.StartsWith(colName, _)), null),
newName = if matchingKey <> null then
Text.Replace(colName, matchingKey, Record.Field(CustomFieldMap, matchingKey))
else
colName
in
{colName, newName}
),

// Apply renaming
RenamedTable = Table.RenameColumns(Source, RenamedColumnsList)
in

When I test with a sample table I cannot replicate a cyclic error. That leads me to believe the error is being generated in your source table.
Here is an alternative method you can try if you wish. If the cyclic error persists you will have to look at your source for the error.

let
    Source =
    /* Debugging Table
    #table(
        {"customfield_10000", "customfield_10100", "customfield_10103"},
        {
            {1,2,3},
            {4,5,6}
        }
    ),*/ 
    jira_issues, 
    // Define your custom field mappings here 
    CustomFieldMap = 
    { 
        {"customfield_10000", "Development"}, 
        {"customfield_10103", "Original story points"} 
    // Add more mappings as needed 
    },
    RenameColumns =
    Table.RenameColumns(
        Source,
        CustomFieldMap,
        MissingField.Ignore
    )
in
    RenameColumns




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





jgeddes
Super User
Super User

In your step "CustomFieldMap" you are creating a record. In a record the field names do not require quotes. If you change your step to read,

CustomFieldMap = [
customfield_10000 = "Development",
customfield_10103 = "Original story points"
// Add more mappings as needed
]

you should get rid of the error. Also I removed the trailing comma from the customfield_10103 line as it is the last field in the record.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





i changed acording to your suggestion , now below error

KunalMathkar_0-1748524841441.png

 

What does your complete code in the advanced editor look like now?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors