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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kleetus51
Frequent Visitor

Delete all columns between two columns

I have a dataset that fluctuates in the number of columns. I need to do some transformations where I delete all the columns between the columns "Key" and "Config" columns, including the Config column. The number of columns between will fluctuate in name and number and there will be a variable number of columns after "Config". Here are some examples. Any ideas?

 

This:

KeyOrder #ReferenceConfigThicknessWidthLength
11234xyz2306823068
24567abc1.528701.52870
38910def2246822468
42345ghi1.37530681.3753068

Would change to this:

KeyThicknessWidthLength
123068
21.52870
322468
41.3753068

 

This:

KeyOrder #ConfigThicknessWidthLengthTransfer
112342306823068TRUE
245671.528701.52870FALSE
389102246822468FALSE
423451.37530681.3753068TRUE

Would change to this:

KeyThicknessWidthLengthTransfer
123068TRUE
21.52870FALSE
322468FALSE
41.3753068TRUE
1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @kleetus51 ;

You could compete it in power query.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TU5JEoAwCPtLzx2nBbr4lk4P7voD9fUCOuoBkgwkUIrxxhoPSAz7cXIHdDELcqHjxqraoppCTAxdP4irCZCTu5kYxMValpFpbr0Mx2mWIdCbCvSlkl4k8S/rplmYwvOC8v8b9QI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Key = _t, #"Order #" = _t, Reference = _t, Config = _t, Thickness = _t, Width = _t, Length = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Key", Int64.Type}, {"Order #", Int64.Type}, {"Reference", type text}, {"Config", type number}, {"Thickness", type number}, {"Width", Int64.Type}, {"Length", Int64.Type}}),
a = Table.ColumnNames(#"Changed Type"),
start=List.PositionOf(a,"Key"),
end=List.PositionOf(a,"Config"),
#"Demoted Headers" = Table.DemoteHeaders(#"Changed Type"),
T1=Table.ToColumns( #"Demoted Headers"),
select1=List.Range(T1, start,1),
select2=List.Range(T1, end),
result=Table.FromColumns(List.Union({select1,select2})),
#"Promoted Headers" = Table.PromoteHeaders(result, [PromoteAllScalars=true])
in
    #"Promoted Headers"

The final output is shown below:

vyalanwumsft_0-1645432648199.png

 


Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi, @kleetus51 ;

You could compete it in power query.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TU5JEoAwCPtLzx2nBbr4lk4P7voD9fUCOuoBkgwkUIrxxhoPSAz7cXIHdDELcqHjxqraoppCTAxdP4irCZCTu5kYxMValpFpbr0Mx2mWIdCbCvSlkl4k8S/rplmYwvOC8v8b9QI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Key = _t, #"Order #" = _t, Reference = _t, Config = _t, Thickness = _t, Width = _t, Length = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Key", Int64.Type}, {"Order #", Int64.Type}, {"Reference", type text}, {"Config", type number}, {"Thickness", type number}, {"Width", Int64.Type}, {"Length", Int64.Type}}),
a = Table.ColumnNames(#"Changed Type"),
start=List.PositionOf(a,"Key"),
end=List.PositionOf(a,"Config"),
#"Demoted Headers" = Table.DemoteHeaders(#"Changed Type"),
T1=Table.ToColumns( #"Demoted Headers"),
select1=List.Range(T1, start,1),
select2=List.Range(T1, end),
result=Table.FromColumns(List.Union({select1,select2})),
#"Promoted Headers" = Table.PromoteHeaders(result, [PromoteAllScalars=true])
in
    #"Promoted Headers"

The final output is shown below:

vyalanwumsft_0-1645432648199.png

 


Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@kleetus51 , select all the columns you want and remove others, if that can help

The number and names of the columns that need to be deleted will vary. I need a solution that says "delete all columns between "Key" and "Config", regardless of their name and number of columns between them.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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