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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
pect
Helper I
Helper I

Table transformation

Hello everybody,

 

I would like to transform the following table:

 

ContracteTipus contracteContractació any 2017Adjudicat any 2017Contractació any 2018Adjudicat any 2018
1A1000200040002500
2B5600240035005500

 

Into the following:

 

Contracte

Tipus contracte

Estat

Any

Import

1

A

Contractació

2017

1000

1

A

Adjudicat

2017

2000

1

A

Contractació

2018

4000

1

A

Adjudicat

2018

2500

2

B

Contractació

2017

5600

2

B

Adjudicat

2017

2400

2

B

Contractació

2018

3500

2

B

Adjudicat

2018

5500

 

Could anyone give me a hand please?

 

Thank you very much in advance!

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

Select the first 2 columns, unpivot other columns.

Adjust the generated code with regard to the names of the new columns.

Split the Estat column with custom delimiter " any ".
Adjust both lines of the generated code with regard to the names of the new columns.

 

 

let
    Source = Table3,
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Contracte", "Tipus contracte"}, "Estat", "Import"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Estat", Splitter.SplitTextByDelimiter(" any ", QuoteStyle.Csv), {"Estat", "Any"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Estat", type text}, {"Any", Int64.Type}})
in
    #"Changed Type"

 

Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
MarcelBeug
Community Champion
Community Champion

Select the first 2 columns, unpivot other columns.

Adjust the generated code with regard to the names of the new columns.

Split the Estat column with custom delimiter " any ".
Adjust both lines of the generated code with regard to the names of the new columns.

 

 

let
    Source = Table3,
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Contracte", "Tipus contracte"}, "Estat", "Import"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Estat", Splitter.SplitTextByDelimiter(" any ", QuoteStyle.Csv), {"Estat", "Any"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Estat", type text}, {"Any", Int64.Type}})
in
    #"Changed Type"

 

Specializing in Power Query Formula Language (M)

Thank you very much!

 

It certainly works!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.