cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Audi_B
Frequent Visitor

Using Substring to modify column data....Is it possible in Power BI?

Hello all, I have one column in a list showing all accounts with a prefix on all account numbers of "00000". So each of these account numbers show like this: "00000123456789".

 

I know in typical SQL, I can use a simple:  substring([account_num], 6,9), but is there a way to modify this in Power BI using DAX, or any other solution to this?

 

 

Thank you!

 

-B

2 ACCEPTED SOLUTIONS
Sean
Community Champion
Community Champion

@Audi_B

Try this in the Query Editor

 

Substring.png

Actually you want to select Last Characters

View solution in original post

Greg_Deckler
Super User
Super User

@Sean's solution will work for M code. 

 

In DAX, you could create a new column with the following formula:

 

If all account numbers are the same length:

AcctNum = RIGHT([Account Number],9)

If not:

 

AcctNum = MID([Account Number,6,LEN([Account Number]) - 5)

You may have to adjust start number and how many characters you are removing from what LEN returns, but general gist is there.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@Sean's solution will work for M code. 

 

In DAX, you could create a new column with the following formula:

 

If all account numbers are the same length:

AcctNum = RIGHT([Account Number],9)

If not:

 

AcctNum = MID([Account Number,6,LEN([Account Number]) - 5)

You may have to adjust start number and how many characters you are removing from what LEN returns, but general gist is there.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Thank you both for the solution. I ended up creating new column and it's working as needed.

 

Thanks again for quick reply!

 

-B

Sean
Community Champion
Community Champion

If you want to keep the original column - you can hit Duplicate Column first and then Rename and Transform the duplicate so you have access to both columns for reports.

 

EDIT: You never actually permanently Transform your original data even if you don't duplicate the Column.

You can go in the Query Settings => Applied Steps and just delete that step!

Substring2.png

Sean
Community Champion
Community Champion

@Audi_B

Try this in the Query Editor

 

Substring.png

Actually you want to select Last Characters

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors