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
PowerBIUser9901
Advocate II
Advocate II

If text contains “-”, then extract text after “-“ delimiter.

Hi, I need guidance in how can I create a new step in Power Query (not a calculated column) that if text contains “-“ then extract text after “-“ delimiter. I'm having trouble in how I reference the column and previous step.

Screenshot below:

Power Query Question.JPG

 

I included the PBIX file if that helps. Link Below:

https://1drv.ms/u/s!AltxA49hBwkYgetlzTpbpo2qoip6hw?e=zNtDmf

 

I appreciate any help you can provide. Thank you!

1 ACCEPTED SOLUTION

Yes.  I actually started that way but thought it would be harder to explain how to implement it.  But since you asked ...

 

= Table.TransformColumns(#"Added Custom", {{"Person/Device", each if Text.Contains(_, "-") then Text.AfterDelimiter(_,"-") else _, type text}})

 

Right click on the desired previous step in the Applied Steps window and "Insert Step After".  Paste this into the formula bar, and update #"Added Custom" with the name of the actual previous step.

 

FYI you could also use the previous approach, delete the original column, and rename the added one to the same name.  But I also like to transform columns directly too when I can.

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
RajivRavichand
Frequent Visitor

Hi Im also facing same kind of secnario, I used below expression but facing issue. Can you please check is there any issue in below DAX.

 

= Table.AddColumn(#"Duplicated Column", "Region", each if Text.Contains(_, "-") then Text.AfterDelimiter([#"Region/Division"], "_") else _, type text)

 

issue:  
Expression.Error: We cannot convert a value of type Record to type Text.
Details:
Value=
Entity=90000 | Hong Kong Div 380
Region/Division=APS_AME_ASIA
Reconciliation Object=90000_45000
Description=Called up Share Capital
Risk Rating=Medium Risk
Currency=HKD
General Ledger Data=-5000000
Explanation Items Amount=-5000000
Reconciling Items Amount=0
Unexplained difference=0
Unexplained percentage=0
Reconciliation Status=To reconcile
Reconciler=BHAVANI.AYASAMY@AGGREKO.COM | BHAVANI AYASAMY
Reconciler Due Date=10/30/2022
Reconciler status=û
Late reconciliation?=
Reviewer=WEI.DONG@AGGREKO.COM | WEI DONG
Reviewer status=û
1st Approver=
1st Approver status=
2nd Approver=
2nd Approver status=
Scope=In Scope
Tower=FAPE
Comments if not in scope=0
Target completion Date=10/11/2022
Status=Overdue
Reconciler status_1=N
Reviewer status_2=N
1st Approver status_3=
2nd Approver status_4=
ReconcilerName= BHAVANI AYASAMY
Reviewer Name= WEI DONG
First Approver Name=
Second Approver Name=

mahoneypat
Employee
Employee

Add a custom column, with this formula.

if Text.Contains([#"Person/Device"], "-") then Text.AfterDelimiter([#"Person/Device"],"-") else [#"Person/Device"]

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks @mahoneypat I appreciate it. Is there a way to use this code as a next step in my query and edit the existing column rather than create a custom column?

Yes.  I actually started that way but thought it would be harder to explain how to implement it.  But since you asked ...

 

= Table.TransformColumns(#"Added Custom", {{"Person/Device", each if Text.Contains(_, "-") then Text.AfterDelimiter(_,"-") else _, type text}})

 

Right click on the desired previous step in the Applied Steps window and "Insert Step After".  Paste this into the formula bar, and update #"Added Custom" with the name of the actual previous step.

 

FYI you could also use the previous approach, delete the original column, and rename the added one to the same name.  But I also like to transform columns directly too when I can.

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you @mahoneypat . I really do appreciate your help and clear instructions. 

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
Top Kudoed Authors