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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jvs5899
Frequent Visitor

Table Transformation

I am working on a board for my quality department and have hit a brick wall. We require parts to be qualified prior to shipment to us from our suppliers. We have a firm date the current version of the part is approved. Per our procedure, they have to requalify the part if there is a 2 year gap in shipments from the last qualification date. The table for the dock gives the part numbers and dates recieved. I have another table that is the last qualification dates. I have included some sample data below, the real tables involve thousand of shipments and parts. I was thinking of doing a transformation where I turn the table so that each part is a row and each column is a reciept date, then do a custom column with the logic for determing the gap between each shipment. However, I don't know how to do it. I have tried the standard transforms but nothing is giving me anything I can use. 

 

Thanks for you help!

 

Part #Qual Date
1G56612314/15/2020
1S458971/15/2020
7U8465407/5/2021
2G5496818/15/2023

 

Part#Rec. Date
1S458972/25/2025
2G54968111/7/2024
7U8465408/16/2024
7U8465407/2/2024
2G5496815/11/2024
7U8465402/11/2024
2G54968111/13/2023
1G56612318/8/2023
7U8465406/9/2023
1G56612314/25/2023
1G566123110/27/2022
1G56612319/27/2022
7U8465406/29/2022
7U8465405/30/2022
7U8465403/31/2022
1G56612313/9/2022
7U8465402/11/2022
1G56612311/25/2022
1G566123112/26/2021
1G566123110/27/2021
1G56612318/8/2021
7U8465407/15/2021
1G56612315/10/2021
1G56612313/26/2021
1G56612311/7/2021
1G566123112/8/2020
1G56612319/17/2020
1G56612316/14/2020
1S458974/8/2020
1G56612315/15/2020
2 ACCEPTED SOLUTIONS
Omid_Motamedise
Super User
Super User

Hi, to put the dates on the columns and determine the part in thefirst column, copy thefollowing formula and past it into your advance editor

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vcy7DcAwCEXRXagtGTA/T+ABolQW+68RYqVJe67e2xtoqRnxIGggnbQzMkK2KpdoTC+nn/sdYipYwftxOs5LZVq8R/ENBmQ+", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Part #" = _t, #"Qual Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Part #", type text}, {"Qual Date", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 1),
    #"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[#"Qual Date"]), "Qual Date", "Custom", List.Sum)
in
    #"Pivoted Column"

If my answer helped solve your issue, please consider marking it as the accepted solution.

View solution in original post

Akash_Varuna
Super User
Super User

Hi @jvs5899 Could you try this please 

let
   
    QualTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vcy7DcAwCEXRXagtGTA/T+ABolQW+68RYqVJe67e2xtoqRnxIGggnbQzMkK2KpdoTC+nn/sdYipYwftxOs5LZVq8R/ENBmQ+", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Part #" = _t, #"Qual Date" = _t]),
    QualChangedType = Table.TransformColumnTypes(QualTable,{{"Part #", type text}, {"Qual Date", type date}}),

    
    RecTable = Excel.CurrentWorkbook(){[Name="ReceiptTable"]}[Content],
    RecChangedType = Table.TransformColumnTypes(RecTable,{{"Part #", type text}, {"Rec. Date", type date}}),

    
    MergedTable = Table.NestedJoin(RecChangedType, "Part #", QualChangedType, "Part #", "Qualification", JoinKind.LeftOuter),
    ExpandedTable = Table.ExpandTableColumn(MergedTable, "Qualification", {"Qual Date"}),

    
    FilteredTable = Table.SelectRows(ExpandedTable, each [Rec. Date] >= [Qual Date]),

    
    GroupedTable = Table.Group(FilteredTable, {"Part #"}, {
        {"Data", each Table.Sort(_, {{"Rec. Date", Order.Ascending}})}
    }),

    // Step 6: Add Gap Days Column for Consecutive Shipments
    AddGapColumn = Table.TransformColumns(GroupedTable, {
        {"Data", each Table.AddColumn(_, "Gap Days", (row) =>
            if Table.RowCount(_) = 1 then null
            else let
                CurrentIndex = Table.PositionOf(_, row),
                PreviousDate = if CurrentIndex > 0 then _[Rec. Date]{CurrentIndex - 1} else null
            in if PreviousDate = null then null else Duration.Days(row[Rec. Date] - PreviousDate))
        )}
    }),

    
    FlattenedTable = Table.ExpandTableColumn(AddGapColumn, "Data", {"Part #", "Rec. Date", "Qual Date", "Gap Days"}),
    AddRequalificationFlag = Table.AddColumn(FlattenedTable, "Requires Requalification", each
        if [Gap Days] <> null and [Gap Days] > 730 then "Yes" else "No")
in
    AddRequalificationFlag

View solution in original post

5 REPLIES 5
v-aatheeque
Community Support
Community Support

Hi @jvs5899 ,

If our response addressed by the community member for your query, please mark it as Accept Answer and click Yes if you found it helpful.

Should you have any further questions, feel free to reach out.
Thank you for being a part of the Microsoft Fabric Community Forum!

Hi @jvs5899 ,

we wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.

 

If our response has addressed by @Akash_Varuna @Omid_Motamedise your query, please accept it as a solution so that other community members can find it easily.


Thank you.

Hi @jvs5899 ,

we wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.

 

If our response has addressed by @Akash_Varuna @Omid_Motamedise your query, please accept it as a solution so that other community members can find it easily.

Akash_Varuna
Super User
Super User

Hi @jvs5899 Could you try this please 

let
   
    QualTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vcy7DcAwCEXRXagtGTA/T+ABolQW+68RYqVJe67e2xtoqRnxIGggnbQzMkK2KpdoTC+nn/sdYipYwftxOs5LZVq8R/ENBmQ+", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Part #" = _t, #"Qual Date" = _t]),
    QualChangedType = Table.TransformColumnTypes(QualTable,{{"Part #", type text}, {"Qual Date", type date}}),

    
    RecTable = Excel.CurrentWorkbook(){[Name="ReceiptTable"]}[Content],
    RecChangedType = Table.TransformColumnTypes(RecTable,{{"Part #", type text}, {"Rec. Date", type date}}),

    
    MergedTable = Table.NestedJoin(RecChangedType, "Part #", QualChangedType, "Part #", "Qualification", JoinKind.LeftOuter),
    ExpandedTable = Table.ExpandTableColumn(MergedTable, "Qualification", {"Qual Date"}),

    
    FilteredTable = Table.SelectRows(ExpandedTable, each [Rec. Date] >= [Qual Date]),

    
    GroupedTable = Table.Group(FilteredTable, {"Part #"}, {
        {"Data", each Table.Sort(_, {{"Rec. Date", Order.Ascending}})}
    }),

    // Step 6: Add Gap Days Column for Consecutive Shipments
    AddGapColumn = Table.TransformColumns(GroupedTable, {
        {"Data", each Table.AddColumn(_, "Gap Days", (row) =>
            if Table.RowCount(_) = 1 then null
            else let
                CurrentIndex = Table.PositionOf(_, row),
                PreviousDate = if CurrentIndex > 0 then _[Rec. Date]{CurrentIndex - 1} else null
            in if PreviousDate = null then null else Duration.Days(row[Rec. Date] - PreviousDate))
        )}
    }),

    
    FlattenedTable = Table.ExpandTableColumn(AddGapColumn, "Data", {"Part #", "Rec. Date", "Qual Date", "Gap Days"}),
    AddRequalificationFlag = Table.AddColumn(FlattenedTable, "Requires Requalification", each
        if [Gap Days] <> null and [Gap Days] > 730 then "Yes" else "No")
in
    AddRequalificationFlag
Omid_Motamedise
Super User
Super User

Hi, to put the dates on the columns and determine the part in thefirst column, copy thefollowing formula and past it into your advance editor

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vcy7DcAwCEXRXagtGTA/T+ABolQW+68RYqVJe67e2xtoqRnxIGggnbQzMkK2KpdoTC+nn/sdYipYwftxOs5LZVq8R/ENBmQ+", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Part #" = _t, #"Qual Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Part #", type text}, {"Qual Date", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 1),
    #"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[#"Qual Date"]), "Qual Date", "Custom", List.Sum)
in
    #"Pivoted Column"

If my answer helped solve your issue, please consider marking it as the accepted solution.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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