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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
matdub40
Helper II
Helper II

How to delete everything after a dash and put the remaining text on 4 characters in DAX?

I have in Visual Studio a table `Y2_Sales` which contains a column "`color`" with values like this :

85-GREY MARLE
90-BLACK
90-BLACK
1000-WHITE
49-NAVY
90-BLACK
3021-BONE

I would like to make a calculated column in my template and delete everything after the dash and put the remaining numbers on 4 characters, which would give :

0085
0090
0090
1000
0049
0090
3021

I tried this formula but it returns me for example `90-` how to remove this last dash?

=LEFT([color],
     IF (SEARCH("-",[color],1,0) > 0,
         SEARCH("-",[color],1,0),
           LEN([color])
          )
      )


Could someone help me?

 

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi, @matdub40 

I am not sure if you want to do this in Power Query Editor.

I think it is a bit easier doing this in Power Query Editor like below (link down below)

 

Picture8.png

 

https://www.dropbox.com/s/oxp7d0nks97tort/matdub.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hi @Jihwan_Kim ,

 

Thank you for your answer, I will look into it, but I would prefer to do it in Visual Studio with a calculated column without having to modify the Power BI part.

 

You have made two distinct columns that separate my two values, I have only one column your two columns separated by a dash like: 90-BLACK

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors