Power Query: Find old procedure and match with new one into a new query.

mduntley

Board Regular
Joined
May 23, 2015
Messages
134
Office Version
  1. 365
Platform
  1. Windows
I have a table I am doing in power query, but i am trying to do something that i cant find out


I have a query, which has column a to c with other data. I am trying to make it so in another query it to show what is the old procedure and what is the new one.

The new Procedure is the MAX of the CPT count, and all the old are the ones that are not the max count. I need a new query as i need to preserve the original one

Book1
ABCDEFG
1Query 1Query 2
2procedurecpt codeCountOld ProcedureCPTNew Procedure
376100081336591176100081336591300000003
4300000003365913426000000496361510000097
526000000496361226000000196365510000098
6510000097963613926000000396366510000455
7260000001963651472000002296367940000017
8510000098963652945600011596368450000137
9260000003963661226000000896372510000100
10510000455963662676100096196402331000002
1172000002296367551000010496417335000005
12940000017963672928000002396523510000106
1345600011596368176100004696523510000106
144500001379636824
15260000008963722
165100001009637254
17761000961964021
183310000029640216
19510000104964174
203350000059641713
21280000023965232
22761000046965235
235100001069652325
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G13Expression=#REF!<>$B13textNO
A3:C22Expression=$B2<>$B3textNO
A3:C23Expression=#REF!<>$B3textNO
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Please disregarded the condition formatting, If its cant be done on a new query, i can make due with the same query
 
Upvote 0
Load your table to Power Query Editor.
Duplicate your table (PQ will name it Table1 (2)
Then Join the two tables in Left Outer Join based on the cpt code

Here is the Mcode to show that join and subsequent steps to achieve the expected results.

Power Query:
let
    Source = Table.NestedJoin(Table1, {"cpt code"}, #"Table1 (2)", {"cpt code"}, "Table1 (2)", JoinKind.LeftOuter),
    #"Expanded Table1 (2)" = Table.ExpandTableColumn(Source, "Table1 (2)", {"procedure"}, {"Table1 (2).procedure"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Table1 (2)", "Custom", each if [procedure]=[#"Table1 (2).procedure"] then null else [procedure]),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] <> null)),
    #"Removed Duplicates" = Table.Distinct(#"Filtered Rows", {"cpt code"}),
    #"Removed Columns" = Table.RemoveColumns(#"Removed Duplicates",{"Count", "Custom"})
in
    #"Removed Columns"
 
Upvote 0

Forum statistics

Threads
1,215,475
Messages
6,125,028
Members
449,205
Latest member
Eggy66

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