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! Request now

Reply
Borja204
Helper II
Helper II

Flatten excel matrix when importing into powerBi

Hi,

 

First of all I'm very new to PowerBi.

 

My problem is about importing the data into powerBi. I have to import an excel file as datasource. I can't touch that excel and the data comes in the following format:

 

 202001202001202001202002202002202002202003202003202003
 Value1Value2Value3Value1Value2Value3Value1Value2Value3
Car 11456755278
Car 25667879887789983

 

When importing the file and to be able to use it for my dashboards and metrics I need to transform (qith the query editor) to the following format:

 

CarNameDateValue1Value2Value3
Car 1202001145
Car 12020026755
Car 1202003278
Car 2202001566787
Car 2202002988778
Car 22020039983

 

I'm totally lost in this ( at least I know the format I need to use the data).

 

Any help is apreciated,

 

Big thanks in advance and regards,

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello @Borja204,

I did some testing with the sample you provided and I came up with the following solution:

  1. Load data and make sure "Use first row as header is not being used" (This will cause issues with duplicate column names)
  2. Transpose the table
  3. Promote Header (This will make it so the car column gets created in the next step
  4. Unpivot Car 1 and Car 2
  5. Now re-pivot column "_1" with the Value as the value column => go into advanced and set aggregation to "Dont Aggregate"

Step 5 is optionial to recieve the data as per format, personally i'd rather skip this last step.

Here is the full code based on an input table:

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "i45WUlDSUTIyMDIwMMTNMMLNMMbCiNWBGBuWmFOaaghjGMEYxmRKgYx1TixSAMmBsAkQmwKxmTmUAcIg9SC+BVw5SMTUDKbOAkRYWsBY5iCWJUwIaEcsAA==", 
          BinaryEncoding.Base64
        ), 
        Compression.Deflate
      )
    ), 
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table[
        Column1 = _t, 
        Column2 = _t, 
        Column3 = _t, 
        Column4 = _t, 
        Column5 = _t, 
        Column6 = _t, 
        Column7 = _t, 
        Column8 = _t, 
        Column9 = _t, 
        Column10 = _t
      ]
  ),
  #"Transposed Table" = Table.Transpose(Source),
  #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars = true]),
  #"Unpivoted Columns" = Table.UnpivotOtherColumns(
    #"Promoted Headers", 
    {" ", " _1"}, 
    "Attribute", 
    "Value"
  ),
  #"Pivoted Column" = Table.Pivot(
    #"Unpivoted Columns", 
    List.Distinct(#"Unpivoted Columns"[#" _1"]), 
    " _1", 
    "Value"
  ),
  #"Changed Type1" = Table.TransformColumnTypes(
    #"Pivoted Column", 
    {{" ", Int64.Type}, {"Value1", Int64.Type}, {"Value2", Int64.Type}, {"Value3", Int64.Type}}
  )
in
  #"Changed Type1"

 

Hope it helps

 

Kind regards
Joren Venema

Data & Analytics Consultant
If this reply solved your question be sure to mark this post as the solution to help others find the answer more easily. 

 

View solution in original post

5 REPLIES 5
FarhanAhmed
Community Champion
Community Champion

I think you need to do following

 

- In transformation you first need to "Transpose" rows into columns

Transpose001.png

 

 

 

 

 

 

 

 

 

-- Promote First row as headers

Transpose002.png

 

---UnPivot Other Columns by select Column1 & 2

Transpose003.png

 

 

 

I hope this helps you what you are trying to achieve

 







Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!

Proud to be a Super User!




Thank you mate, it helped me, just the last repivot step missing but the screenshots helped me a lot!

amitchandak
Super User
Super User

@Borja204 , you have transpose and unpivot, but need to have one header, not 2

https://radacad.com/pivot-and-unpivot-with-power-bi
Transpose : https://yodalearning.com/tutorials/power-query-helps-transposing-data/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hello @Borja204,

I did some testing with the sample you provided and I came up with the following solution:

  1. Load data and make sure "Use first row as header is not being used" (This will cause issues with duplicate column names)
  2. Transpose the table
  3. Promote Header (This will make it so the car column gets created in the next step
  4. Unpivot Car 1 and Car 2
  5. Now re-pivot column "_1" with the Value as the value column => go into advanced and set aggregation to "Dont Aggregate"

Step 5 is optionial to recieve the data as per format, personally i'd rather skip this last step.

Here is the full code based on an input table:

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "i45WUlDSUTIyMDIwMMTNMMLNMMbCiNWBGBuWmFOaaghjGMEYxmRKgYx1TixSAMmBsAkQmwKxmTmUAcIg9SC+BVw5SMTUDKbOAkRYWsBY5iCWJUwIaEcsAA==", 
          BinaryEncoding.Base64
        ), 
        Compression.Deflate
      )
    ), 
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table[
        Column1 = _t, 
        Column2 = _t, 
        Column3 = _t, 
        Column4 = _t, 
        Column5 = _t, 
        Column6 = _t, 
        Column7 = _t, 
        Column8 = _t, 
        Column9 = _t, 
        Column10 = _t
      ]
  ),
  #"Transposed Table" = Table.Transpose(Source),
  #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars = true]),
  #"Unpivoted Columns" = Table.UnpivotOtherColumns(
    #"Promoted Headers", 
    {" ", " _1"}, 
    "Attribute", 
    "Value"
  ),
  #"Pivoted Column" = Table.Pivot(
    #"Unpivoted Columns", 
    List.Distinct(#"Unpivoted Columns"[#" _1"]), 
    " _1", 
    "Value"
  ),
  #"Changed Type1" = Table.TransformColumnTypes(
    #"Pivoted Column", 
    {{" ", Int64.Type}, {"Value1", Int64.Type}, {"Value2", Int64.Type}, {"Value3", Int64.Type}}
  )
in
  #"Changed Type1"

 

Hope it helps

 

Kind regards
Joren Venema

Data & Analytics Consultant
If this reply solved your question be sure to mark this post as the solution to help others find the answer more easily. 

 

 You are a beast!!!

 

Thank you mate your instructions guided me into the correct approach with the real data (which was a bit diferent)

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.

Top Solution Authors