Modify Power Query Custom Function to select Column

brawnystaff

Board Regular
Joined
Aug 9, 2012
Messages
104
Office Version
  1. 365
I am using the Custom Function below to look for duplicate data in a table by two columns. When invoked, it gives me a drop down to search for Table, but I have to manually input the column names. Any ideas as to modify code to have the column names be drop-down list as well? Tried various declarations with no luck. Thanks.

Power Query:
let Dup = (DataTable as table, CCN as text, ClaimLine as text) =>

let
    Source = DataTable,
    #"Changed Type" = Table.TransformColumnTypes(Source,{{CCN, Int64.Type}, {ClaimLine, type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1),
    #"Grouped Rows" = Table.Group(#"Added Index", {CCN}, {{"Data", each _, type table [CCN=nullable number, ClaimLine=nullable text, Index=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Data],"Instance",1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {CCN, ClaimLine, "Index", "Instance"}, {CCN, ClaimLine, "Index", "Instance"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded Custom", "Occurrence", each if [Instance] = 1 then "Original" else "Duplicate"),
    #"Sorted Rows" = Table.Sort(#"Added Conditional Column",{{"Index", Order.Ascending}}),
    #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Index", "Instance"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{CCN, Int64.Type}, {ClaimLine, type text}, {"Occurrence", type text}})
in
    #"Changed Type1"
    in
    Dup
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,214,544
Messages
6,120,126
Members
448,947
Latest member
test111

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