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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
koorosh
Post Partisan
Post Partisan

count back slash

Hi Everybody, I have a table with a column "folder path". It has values like the following:(examples)

C:\koorosh\apple\documents

C:\mac\user

C:\iphone\data\package\app

 

I want to find the number of subfolder that the file is located. It seems one solution is to count the back slash but I got an error when adding custom column with the following code: List.Count(Text.split([folder path]),"\")) What is the solution, please?

1 ACCEPTED SOLUTION
ThxAlot
Super User
Super User

Easy enough,

ThxAlot_0-1722102846144.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


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


)



View solution in original post

6 REPLIES 6
ThxAlot
Super User
Super User

Easy enough,

ThxAlot_0-1722102846144.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


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


)



Greg_Deckler
Super User
Super User

@koorosh Also, your orginal formula has 2 syntax errors in it, here is the correct version:

List.Count(Text.Split([folder path],"\"))

M is case sensitive so Text.Split, not Text.split and you ended your Text.Split early with an errant )



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

koorosh_0-1722106917665.png

Hi Grep, please check the above result!

@koorosh Simple fix, just subtract 1:

List.Count(Text.Split([Column1],"\")) - 1


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks Greg. I knew simple fix . I just let you know the result

Greg_Deckler
Super User
Super User

@koorosh You should be able to easily collapse this down to a single column:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PcxBDoAgDAXRu7D2BG49Br+LBhsxCG0o3N+oidvJy8QYthUoql09A2x2CbBrmlXa8EDLJyonYLr0v5yWtT2WBwPGqfAh7yEQ3Q==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Column1", "Column1 - Copy"),
    #"Replaced Value" = Table.ReplaceValue(#"Duplicated Column","\","",Replacer.ReplaceText,{"Column1 - Copy"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value", "Custom", each Text.Length([Column1]) - Text.Length([#"Column1 - Copy"]))
in
    #"Added Custom"


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
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!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.