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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Query_query
Regular Visitor

Using power query in powerbi to transform an excel sheet data

Hi

 

I am new to power bi power query editor. Can someone please help me with transforming the data in excel format (row 1-7) to the data readable format for powerbi?

 

I have tried to use transpose and pivot without much success 😞

 

 

  TownSgMyVn 
  CcySgdMyrVnd 
  Rate123 
CodeTypeProduct    
1RatedCash100200300 
2UnratedLoan400500600 
3UnratedBond700800900 
       
       
       
       
       
CodeTypeProductBalanceTownCcyRate
1RatedCash100SgSgd1
1RatedCash200MyMyr2
1RatedCash300VnVnd3
2UnratedLoan400SgSgd1
2UnratedLoan500MyMyr2
2UnratedLoan600VnVnd3
3UnratedBond700SgSgd1
3UnratedBond800MyMyr2
3UnratedBond900VnVnd3
3 REPLIES 3
wdx223_Daniel
Super User
Super User

import your data without header as Source

wdx223_Daniel_0-1692670792644.png

then input this code as Custom1

= let a=Table.ToColumns(Source),b=Table.ToRows(Source) in #table(List.FirstN(b{3},3)&{"Balance"}&List.FirstN(a{2},3),List.TransformMany(List.Skip(b,4),each List.Skip(List.Zip({_,a}),3),(x,y)=>List.FirstN(x,3)&{y{0}}&List.FirstN(y{1},3)))

wdx223_Daniel_1-1692670855883.png

 

Thanks, this works for a table format. How can I modify the code to work with a worksheet?

Anonymous
Not applicable

Hi @Query_query 

You can put the following code to Advanced Editor in power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQpKLElNAdLOicUZQMrQwABIBqeDCZC4oVKsDlaVRmCVvpVgoggkgEulMVhlWB6YAIkbg1UaAVmheUVQtT75iSAFJtjtx6rWFLsLsKo1w+4GYxS1TvlgKXPsbsCq1gK7G7CqtcTihlgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Type = _t, Product = _t, Balance = _t, Town = _t, Ccy = _t, Rate = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Type", type text}, {"Product", type text}, {"Balance", Int64.Type}, {"Town", type text}, {"Ccy", type text}, {"Rate", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type", {{"Rate", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Changed Type", {{"Rate", type text}}, "en-US")[Rate]), "Rate", "Balance", List.Sum),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Town", "Ccy"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Code", "Type", "Product"}, {{"1", each List.Sum([1]), type nullable number}, {"2", each List.Sum([2]), type nullable number}, {"3", each List.Sum([3]), type nullable number}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Grouped Rows",{{"1", Int64.Type}, {"2", Int64.Type}, {"3", Int64.Type}})
in
    #"Changed Type1"

Output

vxinruzhumsft_0-1692668354184.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors