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
Legend_11
Helper III
Helper III

Transform Table

I want to transfrom the data as mentioned below, is there any way I could achieve this either in powerquery or either in front end

WeekMaterialSALESPROFITDiscount WeekMaterialSALESPROFITDiscount
1A324 1A11  
1B415 2A11  
1C336 3A11  
1D346 4A 22 
1E657 5A 22 
1F767 6A  33
      7A  33
      8A  33
      9A  33
      1B11  
      2B11  
      3B11  
      4B11  
      5B 22 
      6B  33
      7B  33
      8B  33
      9B  33
      10B  33
3 REPLIES 3
BA_Pete
Super User
Super User

Hi @Legend_11 ,

 

Can you explain the logic of how to get from table1 to table2 please?

I can't see any type of pattern between the data in each table.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




for example I will take first row, 

Material A has 3 sales, I want to split the rows to 3 and also add+1 to the week  , nexxt profit has to come two rows (numbers 11,22,33 are just random int i am using) + continue the addition of week 

 

 

Ok. You can create and expand a list that runs from 1 to the sum of [SALES], [PROFIT], and [Discount], like this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIGYiMgNlGK1YlWcgKzdJQMgdgULOIMVQPCZmARFyjPBC7iCmaBdOgomYNF3MAsiChQJBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Material = _t, SALES = _t, PROFIT = _t, Discount = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"Material", type text}, {"SALES", Int64.Type}, {"PROFIT", Int64.Type}, {"Discount", Int64.Type}}),

    addWeek = Table.AddColumn(chgTypes, "Week", each {1..List.Sum({[SALES],[PROFIT],[Discount]})}),
    expandWeek = Table.ExpandListColumn(addWeek, "Week")

in
    expandWeek

 

Output:

BA_Pete_0-1693466633356.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




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.

Top Solution Authors
Top Kudoed Authors