Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Guys,
I have a column where i need to replace some texts with one single text, it is a project name column and i need to merge diferent names by a single standard name. example:
Project_A_BR -> ProjectA-BR
ProjeactA-BR -> ProjectA-BR
Project-ABR -> ProjectA-BR
The text values are in a single collumn
I can use a text replace function to do it, but i was looking for a more "elegant" solution, anyonw can help me?
Solved! Go to Solution.
Hi @Anonymous
If you only have those 4 variations, the easiest way to do this in DAX would be with the SWITCH function, as follows:
Calculated Column =
SWITCH (
TRUE(),
Table1[ColumnName] = "CRM CITRIX BR", "CRM CITRIX - BR",
Table1[ColumnName] = "CRM CITRIX PROD BR", "CRM CITRIX - BR",
Table1[ColumnName] = "CRM CITRIX 2 PROD BR", "CRM CITRIX - BR",
Table1[ColumnName] = "CRM VITRIX BRAZIL", "CRM CITRIX - BR",
Table1[ColumnName]
)
You could achieve the same result in Power Query using Add Column>>Conditional Column.
Best regards,
Martyn
If I answered your question, please help others by accepting it as a solution.
Hi @Anonymous
Given that you've posted this in the 'DAX Commands and Tips' forum, my answer explains one way to do this in DAX.
However, I would reccommend that you fix this column in the Query Editor during data load.
There are various ways to achieve this in DAX but I'm assuming you don't want to hardcode the incorrect values into your expression (in an IF statement, for example)?
One alternative approach is to use a series of nested SUBSTITUTE functions to remove any unnecessary characters or incorrect spellings.
Then use the REPLACE function to add the "-".
Correct Project Name =
REPLACE (
SUBSTITUTE (
SUBSTITUTE (
SUBSTITUTE ( Table1[Name], "_", "" ),
"-", ""
),
"Projeact", "Project"
),
9, 0, "-"
)
Doesn't look very elegant to me... but it works! 🙂
Best regards,
Martyn
If I answered your question, please help others by accepting it as a solution.
HI Martyn,
Thanks for your reply.
Your solution could fit in some cases, but i was looking for my data and it does not fit, i will explain with a real example, hope you can help
I have a column called Project, and there are some variations of same project, ex:
CRM CITRIX BR
CRM CITRIX PROD BR
CRM CITRIX 2 PROD BR
CRM VITRIX BRAZIL
i did a cleanup on the project data and merged the above names in just one :
CRM CITRIX - BR
the previous data from months before the cleanup are with wrong variations and i need to replace it to have the costs for project CRM CITRIX - BR in the unique Value to create the reports.
Do you think there is a way to do this replace?
Hi @Anonymous
If you only have those 4 variations, the easiest way to do this in DAX would be with the SWITCH function, as follows:
Calculated Column =
SWITCH (
TRUE(),
Table1[ColumnName] = "CRM CITRIX BR", "CRM CITRIX - BR",
Table1[ColumnName] = "CRM CITRIX PROD BR", "CRM CITRIX - BR",
Table1[ColumnName] = "CRM CITRIX 2 PROD BR", "CRM CITRIX - BR",
Table1[ColumnName] = "CRM VITRIX BRAZIL", "CRM CITRIX - BR",
Table1[ColumnName]
)
You could achieve the same result in Power Query using Add Column>>Conditional Column.
Best regards,
Martyn
If I answered your question, please help others by accepting it as a solution.
HI Martyn,
Thanks, i guess now its fit perfectly to my need!
I am getting this error when trying to add a column with DAX that you suggestes
Error > Argument '14' in SWITCH funtion is required.
HI Martyn
i found the problem, "Unknow" parameter at the end of DAX was missing now worked
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
8 | |
6 | |
5 |
User | Count |
---|---|
17 | |
14 | |
10 | |
9 | |
6 |