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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
kulkarni21vinee
Frequent Visitor

Find, If its not a last record

I wanted to append delimiter | (pipe symbol) to differentiate each Maintenance Record, of a List, unless it’s not last record

Also, specific Maintaince Records would be filtering out based upon if-else conditions.

e.g.:

 

kulkarni21vinee_1-1732900882590.png

 

with below M query, when I loop through each Maintenance Description it append an unnecessary  | (pipe symbol) at the end. 

 

#"Extracted Values" = Table.TransformColumns(
#"Filtered Rows",
{
"WorkLoadDetails",
each Text.Combine(
List.Transform(
_,
each (
if not Text.StartsWith(Record.Field(_, "MaintenanceDescription"), "Specific Code")
then
Record.Field(_, "MaintenanceDescription")
else
""
)& (
if not Text.StartsWith(Record.Field(_, "MaintenanceDescription"), "Specific Code")
then
"|"
else
""
)
)
),
type text
}
)
in
#"Extracted Values"

 

My need is to remove remove extra pipe delimiter, which gets added after last record for each row (sample example shown with 3 red arrows in second screenshot).

 

 

2 ACCEPTED SOLUTIONS

pls try this

=Text.BeforeDelimiter([Column1],"|",RelativePosition.FromEnd)

Screenshot_4.png

View solution in original post

pl try

=Text.Combine( List.RemoveLastN( Text.ToList([Column1]),1))

Screenshot_6.png

View solution in original post

14 REPLIES 14
Ahmedx
Super User
Super User

pls try this

[
    a= Text.Replace([WorkLoadDetails],"SC1, ",""),
b = Splitter.SplitTextByAnyDelimiter({", "})(a),
c = Text.Combine(b,"|")
][c]

Screenshot_3.png

Thank you @Ahmedx @ example which was shared, was just for demo. I have edited post with how data and entire query actually looks like just to give clearity

the easy way is to add a new sun and write

 

 

=Text.Range([Column1],0,Text.Length([Column1])-1)

 

 

Screenshot_5.png

This is very interesting solution, however, it replaces delimiter pipe between all the WorkLoadDetails. I just need to remove extra which gets added after last record.

it replaces only the last character

but you just need to add a new column

kulkarni21vinee_0-1732957401382.png

 

pls try this

=Text.BeforeDelimiter([Column1],"|",RelativePosition.FromEnd)

Screenshot_4.png

Doesn't work for multiple values, This strips off all values post second field record

 

kulkarni21vinee_0-1732991175795.png

 

Really appriciate you help.

pl try

=Text.Combine( List.RemoveLastN( Text.ToList([Column1]),1))

Screenshot_6.png

Thank you @Ahmedx ! Appreciate your help

Omid_Motamedise
Memorable Member
Memorable Member

Use the following code

 

 

let
#"Filtered Rows" = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwMFTQVQh2NtRRCMlXSMlXcIIxnJVidcAKjIAKIEIuMDk3pdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [WorkLoadDetails = _t]),
Transform = Table.TransformColumns(#"Filtered Rows",{{"WorkLoadDetails", each Text.Replace(Text.Combine(List.RemoveItems(Text.Split(_," "),{"SC1,"})),",","|")}})
in
Transform

Thank you @Omid_Motamedise  example which was shared, was just for demo. I have edited post with how data and entire query actually looks like just to give clearit

Poojara_D12
Solution Sage
Solution Sage

Hi @kulkarni21vinee 

As per my understanding, to avoid appending an extra pipe symbol | at the end, you can use Text.Combine directly with a delimiter without manually adding | . Modify your code as follows:

#"Extracted Values" = Table.TransformColumns(
    #"Filtered Rows",
    { "WorkLoadDetails", each Text.Combine(List.Transform(_, each Record.Field(_, "MaintenanceDescription")), " | ") }
)

The Text.Combine function allows you to specify a delimiter ( " | "  ), and it automatically ensures no trailing delimiter is added. No need to check for the last record manually. 

 

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Please Subscribe my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS 

Thank you @Poojara_D12  for quick response. Rather, I tried that before, but I think I didn't include additional requirement - Sorry about that, (Updated original question). I have to filter out specific MaintenanceDescription thus have to loop in each records and filter not required one and append |. If i use | outside each record field, It appends | to filtered records. e.g. output:  | | ENG IDG OIL/FILTER 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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