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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Pot2000
Regular Visitor

Split colum when value is missing the null value should be in the first colum

I have a data dump where one of the colums contains a period of time that i would like to split in day's hours and minutes.

The data is as follows.

30d 22h 3m
1h 17m
57m

I would like to split the data as below

Dayshoursmin
30223
017
0057

 

Any help is welkom

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

pls try code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjZIUTAyylAwzlWK1YlWMsxQMDSHME1BdCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [
a = Text.Split([Data]," "),
b= List.Transform(a,(x)=> Splitter.SplitTextByCharacterTransition({"0".."9"},(x)=>not List.Contains({"0".."9"},x))(x)),
 c= Table.FromList(b,(x)=>x),
 e= Table.TransformColumns(c,{"Column2",(x)=> if x =
 "d" then "Days" else if x= "h" then "hours" else "min"})  ][e]),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Column1", "Column2"}, {"Column1", "Column2"}),
    #"Pivoted Column" = Table.Pivot(#"Expanded Custom", List.Distinct(#"Expanded Custom"[Column2]), "Column2", "Column1")
in
    #"Pivoted Column"

View solution in original post

3 REPLIES 3
Ahmedx
Super User
Super User

pls try code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjZIUTAyylAwzlWK1YlWMsxQMDSHME1BdCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [
a = Text.Split([Data]," "),
b= List.Transform(a,(x)=> Splitter.SplitTextByCharacterTransition({"0".."9"},(x)=>not List.Contains({"0".."9"},x))(x)),
 c= Table.FromList(b,(x)=>x),
 e= Table.TransformColumns(c,{"Column2",(x)=> if x =
 "d" then "Days" else if x= "h" then "hours" else "min"})  ][e]),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Column1", "Column2"}, {"Column1", "Column2"}),
    #"Pivoted Column" = Table.Pivot(#"Expanded Custom", List.Distinct(#"Expanded Custom"[Column2]), "Column2", "Column1")
in
    #"Pivoted Column"

Works like a charm thank you

Pot2000
Regular Visitor

Some extra info i use the following formulas in excel. And than copy past values and  make numbers from text.
=Iferror(Left(E3;search("d";E3)-1);0)
=iferror(iferror(mid(E3;search("u";E3)-2;2);mid(E3;search("u";E3)-1;1));0)

=iferror(mid(E3;search("m";E3)-2;2);0)

I than load this file into POwerBI.

Howeever i would like to do this in Powerbi since it is someting that comes back every quater with 3 differant dumps.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.