Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more.
Get startedGrow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.
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 @v-xuxinyi-msft 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 @v-xuxinyi-msft 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.
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Ask questions in Eventhouse and KQL, Eventstream, and Reflex.
User | Count |
---|---|
69 | |
35 | |
21 | |
18 | |
15 |
User | Count |
---|---|
127 | |
31 | |
27 | |
24 | |
22 |