Excel Power Query: Trying to produce a file

mduntley

Board Regular
Joined
May 23, 2015
Messages
139
Office Version
  1. 365
Platform
  1. Windows
So I am trying to produce a file in Power Query using two tables. There is a problem that I am facing

1. Table 2 has set dates for a fee schedule and Table 1 shows an effective date of 7/15. I got the 8/31/2022 and 9/18/2022 Dates in, but I also need to get the 7/13 date also as 7/15 will be after 7/13, but I don't need anything before 7/13. I am producing this file and importing it into another program.

Book3
ABCDE
1Table 1
2FSCEffective DateCPTModifierPrice
35577/15/202236590398
43659026319
536590TC79
6
7Table 2
8FEE SCHEDULE IDFEE SCHEDULE NAMEStart Date
9557FSC Name6/1/2021
10557FSC Name10/1/2021
11557FSC Name1/1/2022
12557FSC Name5/2/2022
13557FSC Name7/1/2022
14557FSC Name7/13/2022
15557FSC Name8/31/2022
16557FSC Name9/18/2022
17
18Table I am getting
19FEE SCHEDULE IDStart DateCPTModifierPrice
205578/31/202236590398
215578/31/20223659026319
225578/31/202236590TC79
235579/18/202236590398
245579/18/20223659026319
255579/18/202236590TC79
26
27Result that I want
28FEE SCHEDULE IDStart DateCPTModifierPrice
295577/13/202236590398
303659026319
3136590TC79
325578/31/202236590398
333659026319
3436590TC79
355579/18/202236590398
363659026319
3736590TC79
Sheet1
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    tbl = Table.TransformColumnTypes(Source,{{"Effective Date", type date}}),
    tbl1 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    lst = Table.TransformColumnTypes(tbl1,{{"Start Date", type date}})[Start Date],
    N = List.Count(List.Select(lst, each _ > tbl[Effective Date]{0})) +1,
    ReplaceEffectiveDate = (tbl as table, dt as date) => 
        let 
            lst = Table.ToRecords(tbl),
            rcd = Record.TransformFields(lst{0}, {{"Effective Date", each dt}}),
            Result = Table.FromRecords({rcd} & List.Skip(lst,1))
        in 
            Result,
    tbl2 = List.Accumulate(List.LastN(List.Sort(lst),N), Table.FirstN(tbl,0), (s,c)=> s & ReplaceEffectiveDate(tbl, c)),
    Result = Table.RenameColumns(tbl2,{{"FSC", "Fee Schedule ID"}, {"Effective Date", "Start Date"}})
in
    Result

Book2
ABCDEFGHIJKL
1FSCEffective DateCPTModifierPriceFee Schedule IDStart DateCPTModifierPrice
25577/15/2022365903985577/13/202236590398
336590263193659026319
436590TC7936590TC79
55578/31/202236590398
6FEE SCHEDULE IDFEE SCHEDULE NAMEStart Date3659026319
7557FSC Name6/1/202136590TC79
8557FSC Name10/1/20215579/18/202236590398
9557FSC Name1/1/20223659026319
10557FSC Name5/2/202236590TC79
11557FSC Name7/1/2022
12557FSC Name7/13/2022
13557FSC Name8/31/2022
14557FSC Name9/18/2022
15
Sheet1
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top