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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
CJ_96601
Helper V
Helper V

Extract certain text

Need help to extract as per below example:

 

DateRequired Result
E1E1
E2E2
E3E3
M22
EE.11
EE.22
EE.1111
M1111

 

If data is E1, E2 and E3, all will be extracted into the new column, if not only number will be extracted, some has delimiter some has not.

 

Thanks

2 ACCEPTED SOLUTIONS

Hi @CJ_96601 ,

Adjust to the below:

if Text.Contains([Date], ".0") 
          then Text.AfterDelimiter([Date], ".0") 
else if  Text.Contains([Date], ".") 
          then Text.AfterDelimiter([Date], ".")       
else if Text.Start([Date],1) = "E" and not Text.Contains([Date], ".")  
          then Text.Start([Date],2)
          else 
         Text.Combine(List.RemoveNulls(List.Transform(Text.ToList([Date]),each if Value.Is(Value.FromText(_), type number) then _ else null)))

vluwangmsft_0-1636452507210.png

 

 

Best Regards

Lucien

View solution in original post

Hi @CJ_96601 ,

New custom column like below:

= Table.AddColumn(#"Added Custom", "Custom.1", each if not Text.Contains([Date], ".")  then Text.Range([Date],Text.Length([Date])-1,1) 
 else if  Text.Contains([Date], ".")  and Text.Range([Date],1,1)="X" then "X" 
else Text.Start([Date],1))

vluwangmsft_0-1636524240624.png

 

Best Regards

Lucien

View solution in original post

12 REPLIES 12
mahoneypat
Employee
Employee

You can use an expression like this

 

= if Text.Contains([Date], ".") then Text.AfterDelimiter([Date], ".") else if Text.Start([Date],1) = "E" and Text.Length([Date]) = 2 then [Date] else Text.End([Date],1)

 

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, it works, but i made a mistake on the data source.

 

Please find correct data sample

 

DateRequired Result
E1SE1
E2WE2
E3SE3
M2E2
EE.11
EE.22
EE.1111
M11W11

Hi @CJ_96601 ,

Test like this :

if Text.Contains([Date], ".") 
          then Text.AfterDelimiter([Date], ".") 
else if Text.Start([Date],1) = "E" and not Text.Contains([Date], ".")  
          then Text.Start([Date],2)
          else 
         Text.Combine(List.RemoveNulls(List.Transform(Text.ToList([Date]),each if Value.Is(Value.FromText(_), type number) then _ else null)))

vluwangmsft_0-1636444442953.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckksSVXSUQpKLSzNLEpNUQhKLS7NKVGK1YlWcjUMBsq4GkI4RuEgjhGEYwyWMQZzfI1cgRyohKueIZBjCOMYociApSByvoaG4VBeLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type text}, {"Required Result", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each if Text.Contains([Date], ".") 
          then Text.AfterDelimiter([Date], ".") 
else if Text.Start([Date],1) = "E" and not Text.Contains([Date], ".")  
          then Text.Start([Date],2)
          else 
         Text.Combine(List.RemoveNulls(List.Transform(Text.ToList([Date]),each if Value.Is(Value.FromText(_), type number) then _ else null))))
in
    #"Added Custom"

 

Did I answer your question? Mark my post as a solution!


Best Regards

Lucien

Thanks.   I have some additional data format.  You may refer to the last two items in the table

 

DateRequired Result
E1E1
E2E2
E3E3
M22
EE.11
EE.22
EE.1111
M1111
EE.011
EE.033

 

Hi @CJ_96601 ,

A little adjust:

if Text.Contains([Date], ".0") 
          then Text.AfterDelimiter([Date], ".0") 
      
else if Text.Start([Date],1) = "E" and not Text.Contains([Date], ".")  
          then Text.Start([Date],2)
          else 
         Text.Combine(List.RemoveNulls(List.Transform(Text.ToList([Date]),each if Value.Is(Value.FromText(_), type number) then _ else null)))

Return :

vluwangmsft_0-1636451196662.png

 

Best Regards
Lucien

 

Thanks, it works well.

 

May i kindly ask one more adjustments.  Please refer to last row.

 

DateRequired Result
E1E1
E2E2
E3E3
M22
EE.11
EE.22
EE.1111
M1111
EE.011
EE.033
EX.AA

Hi @CJ_96601 ,

Adjust to the below:

if Text.Contains([Date], ".0") 
          then Text.AfterDelimiter([Date], ".0") 
else if  Text.Contains([Date], ".") 
          then Text.AfterDelimiter([Date], ".")       
else if Text.Start([Date],1) = "E" and not Text.Contains([Date], ".")  
          then Text.Start([Date],2)
          else 
         Text.Combine(List.RemoveNulls(List.Transform(Text.ToList([Date]),each if Value.Is(Value.FromText(_), type number) then _ else null)))

vluwangmsft_0-1636452507210.png

 

 

Best Regards

Lucien

Thanks.

 

May i seek your help as well to get the additional column as follows: (Required Result 1)

 

DateRequired ResultRequired Result1
E1WE1W
E2EE2E
E3SE3S
M2E2E
EE.11E
WE.22W
SA.1111S
M11S11S
EE.011E
SA.033S
EX.AAX

HI @CJ_96601 ,

What is the new output logic added?

 

 

Best Regards

Lucien

Required result 1

 

If there is no delimiter get the last letter  (S; E; or W)

If there is delimeter and get the first letter (S,E, or W), if the second letter is X get the "X"

 

Thanks

 

Hi @CJ_96601 ,

New custom column like below:

= Table.AddColumn(#"Added Custom", "Custom.1", each if not Text.Contains([Date], ".")  then Text.Range([Date],Text.Length([Date])-1,1) 
 else if  Text.Contains([Date], ".")  and Text.Range([Date],1,1)="X" then "X" 
else Text.Start([Date],1))

vluwangmsft_0-1636524240624.png

 

Best Regards

Lucien

Thanks a lot..

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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