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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
IvanS
Helper V
Helper V

Extract text after specific text string

Hi guys,

 

I am trying to get location code from the column Subject in table FACT_Tasks - example below:

 

Logic: If Subject contains (anywhere) the specific text string (AAAA or BBBB), then

- If AAAA - then take 10 characters (including AAAA)

- If BBBB - then take 12 characters (including BBBB)

 

I would prefer to have this in DAX as calculated column and not via Power Query.

 

SubjectLocation code (calculated)
Texttexttext(blank)
Task 1 - AAAA123456AAAA12345
Task Subject Name - BBBB1234567-89BBBB12345-67

 

Thank you
IvanS

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

you can change the numbers 10 and 12 to any other numbers if it is necessary for you

Screenshot_2.png

View solution in original post

6 REPLIES 6
Ksyokz23
Frequent Visitor

How about if I want to do same but this time with Power Query not with DAX 

ThxAlot
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkmtKCmBYqVYHaBAYnG2gqGCroIjEBgaGZuYmiHEg0uTslKTSxT8EnNTgUqcgACixFzXwlIpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Subject = _t]),

    Extracted = Table.AddColumn(Source, "Location code", each if Text.Contains([Subject], "AAAA") then Text.Range([Subject], Text.PositionOf([Subject], "AAAA"), 10) else try Text.Range([Subject], Text.PositionOf([Subject], "BBBB"), 12) otherwise null)
in
    Extracted

ThxAlot_0-1691826204404.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Ahmedx
Super User
Super User

you can change the numbers 10 and 12 to any other numbers if it is necessary for you

Screenshot_2.png

@Ahmedx How about if I want to do same but this time with Power Query not with DAX 

Hi @Ksyokz23 ,

check the response from @ThxAlot in this thread. 

 

@IvanS It worked thank you

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.