Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi experts!
I have a column with text and numbers.
Now I would like to remove the last 2 characters, if it is a number.
From "1A" to "A".
But how with dax?
Solved! Go to Solution.
In Power BI, you can achieve this using DAX (Data Analysis Expressions). You can create a new calculated column or measure depending on your requirement. Here's how you can do it using a calculated column:
Now, you can use the following DAX expression to create a new column:
NewColumn =
IF(
ISNUMBER(VALUE(LEFT(YourTableName[YourColumnName], LEN(YourTableName[YourColumnName])-2))),
LEFT(YourTableName[YourColumnName], LEN(YourTableName[YourColumnName])-2),
YourTableName[YourColumnName]
)
Replace YourTableName with the name of your table and YourColumnName with the name of the column containing the text and numbers.
This DAX expression does the following:
After you've entered the DAX expression, press Enter. It will create a new column in your table with the desired result.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.
Hi @joshua1990
You can use M function in Power Query.
Here is my trying.
My sample:
1. Split Column by Position
2. add a Custom Column
Text.Select([Value.2], {"a".."z", "A".."Z"})
3. Select the two columns that need to be merged
4. remove Value.2 Column
5. Result
Here is the whole M function in Advanced Editor:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WioiIdAmOUorViVYK9vYwNgGzHH28vQwdwUw/72AfIzDL0MjYxM0FwjQ2NDIxhgibGJtCBI1NTN2BQrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Value", type text}}),
#"Split Column by Position" = Table.SplitColumn(#"Changed Type", "Value", Splitter.SplitTextByPositions({0, 2}, true), {"Value.1", "Value.2"}),
#"Added Custom" = Table.AddColumn(#"Split Column by Position", "Custom", each Text.Select([Value.2], {"a".."z", "A".."Z"})),
#"Merged Columns" = Table.CombineColumns(#"Added Custom",{"Value.1", "Custom"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged"),
#"Removed Columns" = Table.RemoveColumns(#"Merged Columns",{"Value.2"})
in
#"Removed Columns"
Best Regards,
Yulia Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
If you don't wan to make changes in M like @Anonymous suggested or use a column. Here is a measure:
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
Proud to be a Super User!
Hi,
If you don't wan to make changes in M like @Anonymous suggested or use a column. Here is a measure:
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
Proud to be a Super User!
Hi @joshua1990
You can use M function in Power Query.
Here is my trying.
My sample:
1. Split Column by Position
2. add a Custom Column
Text.Select([Value.2], {"a".."z", "A".."Z"})
3. Select the two columns that need to be merged
4. remove Value.2 Column
5. Result
Here is the whole M function in Advanced Editor:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WioiIdAmOUorViVYK9vYwNgGzHH28vQwdwUw/72AfIzDL0MjYxM0FwjQ2NDIxhgibGJtCBI1NTN2BQrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Value", type text}}),
#"Split Column by Position" = Table.SplitColumn(#"Changed Type", "Value", Splitter.SplitTextByPositions({0, 2}, true), {"Value.1", "Value.2"}),
#"Added Custom" = Table.AddColumn(#"Split Column by Position", "Custom", each Text.Select([Value.2], {"a".."z", "A".."Z"})),
#"Merged Columns" = Table.CombineColumns(#"Added Custom",{"Value.1", "Custom"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged"),
#"Removed Columns" = Table.RemoveColumns(#"Merged Columns",{"Value.2"})
in
#"Removed Columns"
Best Regards,
Yulia Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
In Power BI, you can achieve this using DAX (Data Analysis Expressions). You can create a new calculated column or measure depending on your requirement. Here's how you can do it using a calculated column:
Now, you can use the following DAX expression to create a new column:
NewColumn =
IF(
ISNUMBER(VALUE(LEFT(YourTableName[YourColumnName], LEN(YourTableName[YourColumnName])-2))),
LEFT(YourTableName[YourColumnName], LEN(YourTableName[YourColumnName])-2),
YourTableName[YourColumnName]
)
Replace YourTableName with the name of your table and YourColumnName with the name of the column containing the text and numbers.
This DAX expression does the following:
After you've entered the DAX expression, press Enter. It will create a new column in your table with the desired result.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
24 | |
10 | |
6 | |
6 | |
6 |
User | Count |
---|---|
29 | |
11 | |
11 | |
10 | |
6 |