Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I have connected power bi with clickhouse database.
my table name is "jira_issues"
i have explained query below
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.
images for reference -
help me to resolve this so i can rename all column names using query.if above query is wrong let me know right query
Solved! Go to Solution.
yes i got ny correct query and query is here
yes i got ny correct query and query is here
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.
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.
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.
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
Proud to be a 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.
Proud to be a Super User! | |
i changed acording to your suggestion , now below error
What does your complete code in the advanced editor look like now?
Proud to be a Super User! | |