Forum Discussion

quincy_p's avatar
quincy_p
Icon for Advocate I rankAdvocate I
8 months ago
Solved

Create a Merged Deadline and Service History Table

Hi all - I have 2 tables that I need to connect or merge. One is a list of all my assets (table: Covered Products) under contract with their Name (unique), Contract Start and End Dates, a Service Frequency and its Installed Product Id (please note that this Id can occur on multiple names).

Then I have my work order table which has Work Order name (unique), Component Id (this is the same as Installed Product Id) and a service date.

 

What I need to do is generate a list of deadlines for each Name under Covered Products using frequency as those deadlines (this is either 6 or 12), so Start Date + Frequency (months) = 1st Deadline and so on until the contract end date has been reached.

Then I need to look up to the Work Orders table to find all Service Dates where the Component matches Installed Product Id and whether each deadline has a service before it. 

 

Below are 2 sample tables:

 

NameFrequencyInstalled Product IDStart DateEnd Date
SCPN-30000112az7703373481/1/20211/1/2026
SCPN-30000212az1471250026/1/20216/1/2024
SCPN-30000312az6782588011/1/20221/1/2027
SCPN-30000412az7552852366/1/20226/1/2026
SCPN-3000056az7096797831/1/20231/1/2026
SCPN-30000612az8288456046/1/20236/1/2026
SCPN-30000712az8444483901/1/20241/1/2029
SCPN-3000086az3301117706/1/20246/1/2029
SCPN-30000912az4203293971/1/20251/1/2028
SCPN-30001012az2297032316/1/20256/1/2029

 

Work Orders:

 

Work Order NameComponent IdStart DateEnd DateService Date
WO-400008az1471250026/1/20216/1/20245/31/2024
WO-400003az2297032316/1/20256/1/20299/8/2028
WO-400005az2297032316/1/20256/1/20297/20/2026
WO-400023az2297032316/1/20256/1/202912/16/2025
WO-400024az2297032316/1/20256/1/20295/4/2026
WO-400007az3301117706/1/20246/1/20297/17/2026
WO-400014az3301117706/1/20246/1/202910/31/2028
WO-400025az3301117706/1/20246/1/20294/14/2027
WO-400001az4203293971/1/20251/1/20285/22/2025
WO-400009az4203293971/1/20251/1/20287/26/2027
WO-400011az4203293971/1/20251/1/20286/23/2026
WO-400020az4203293971/1/20251/1/20289/8/2026
WO-400016az6782588011/1/20221/1/202710/19/2024
WO-400019az6782588011/1/20221/1/20271/23/2024
WO-400022az6782588011/1/20221/1/20278/30/2022
WO-400012az7096797831/1/20231/1/20268/10/2023
WO-400017az7096797831/1/20231/1/202612/11/2023
WO-400018az7096797831/1/20231/1/202612/22/2024
WO-400002az7552852366/1/20226/1/20264/25/2025
WO-400015az7552852366/1/20226/1/20264/5/2024
WO-400013az7703373481/1/20211/1/20268/14/2021
WO-400006az8288456046/1/20236/1/20269/5/2024
WO-400004az8444483901/1/20241/1/20299/22/2027
WO-400010az8444483901/1/20241/1/20293/11/2025
WO-400021az8444483901/1/20241/1/202912/23/2024

 

And in addition, I would need some way to disntinguish between a service being late or on time. For instance with a deadline of 31/12/2025 but I did the service on 15/01/2026 - this should not count as the 2026 deadline. 

 

Expected Result:

 

Product NameFrequencyStart DateEnd DateDeadline #Deadline DateWO NumberService DateOn Time?
SCPN-300001121/1/20211/1/2026131/12/2021WO-12345615/12/2021Yes
SCPN-300001121/1/20211/1/2026231/12/2022WO-12345730/11/2022Yes
SCPN-300001121/1/20211/1/2026331/12/2023WO-12345815/01/2024No
SCPN-300001121/1/20211/1/2026431/12/2024WO-12345910/12/2024Yes
SCPN-300001121/1/20211/1/2026531/12/2025WO-123460  
  • How did you generate the last 3 columns of the desired table?  I do not see the entries under these columns in the Work Orders table.

8 Replies

  • Here's your deadline explosion for the assets table.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZI9CsMwDEbv4jkl+rWkuXspdAwZeo2evk5TIscQD+ZD5vFky8tSXvfn48bQFpapILXt/TEDZmPxrTTjTECYsZZ16kFKEMWQdC/VBP9RBpATrOak7tBpKKMNoHStqpIrcU1NJx9b1e1o5yCqhTmnha+vWFPo5C5afz3UBC+E1oHSlnNAaiRjDKAfnTIDIraR9A95xJGLFAoBU3BYWjSjn0GEBImifQDibnR6Mq5f", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Frequency = _t, #"Installed Product ID" = _t, #"Start Date" = _t, #"End Date" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date", type date}, {"End Date", type date}, {"Frequency", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Deadline", (k)=> List.Generate(()=>Date.AddMonths(k[Start Date],k[Frequency]),each _ <= k[End Date], each Date.AddMonths(_,k[Frequency]))),
        #"Expanded Deadline" = Table.ExpandListColumn(#"Added Custom", "Deadline"),
        #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Deadline",{{"Deadline", type date}})
    in
        #"Changed Type1"

     

    You can now compare that against the service dates.  Not sure what your expected outcome is for the sample data you provided.

     

  • Hi quincy_p 

    Please see the attached pbix. If  this isnt what you're looking for, please a provide a sample result  using the same sample data.

     

    Note: Joins/merges can be a very expensive process in Power Query.

    • quincy_p's avatar
      quincy_p
      Icon for Advocate I rankAdvocate I

      Have updated original post with expected result

  • Hi,

    Based on the 2 tables which you have shared, show the expected result very clearly.

    • quincy_p's avatar
      quincy_p
      Icon for Advocate I rankAdvocate I

      Here would be an example - using the matching Id to find the associated work orders completed against each product name. Then to see if there is a service date within each service period, completed on time. 

       

      Hope that Helps

       

      Product NameFrequencyStart DateEnd DateDeadline #Deadline DateWO NumberService DateOn Time?
      SCPN-300001121/1/20211/1/2026131/12/2021WO-12345615/12/2021Yes
      SCPN-300001121/1/20211/1/2026231/12/2022WO-12345730/11/2022Yes
      SCPN-300001121/1/20211/1/2026331/12/2023WO-12345815/01/2024No
      SCPN-300001121/1/20211/1/2026431/12/2024WO-12345910/12/2024Yes
      SCPN-300001121/1/20211/1/2026531/12/2025WO-123460  
      • Ashish_Mathur's avatar
        Ashish_Mathur
        Icon for Super User rankSuper User

        How did you generate the last 3 columns of the desired table?  I do not see the entries under these columns in the Work Orders table.