Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Say I have a column of ID values in Power BI with many duplicates for each ID value. If I wanted to make a custom column where each ID only appears once and duplicates will have Blank() value. How would I code that?
Solved! Go to Solution.
Hi @nathan_kul ,
Please refer to the following steps. You can adjust the Source step to match your actual data source.
let
Source = Table.FromRecords({[ID = 1], [ID = 2], [ID = 2], [ID = 3], [ID = 3], [ID = 3]}),
#"Grouped Rows" = Table.Group(Source, {"ID"}, {{"Data", each Table.AddIndexColumn(_, "Index", 0, 1, Int64.Type)}}),
#"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Index"}, {"Index"}),
#"Added Custom" = Table.AddColumn(#"Expanded Data", "ID2", each if [Index]=0 then [ID] else null),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
#"Removed Columns"
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Hi @nathan_kul, different approach here:
I've used @Anonymous sample data.
Output
let
Source = Table.FromRecords({[ID = 1], [ID = 2], [ID = 2], [ID = 3], [ID = 3], [ID = 3]}),
GroupedRows = Table.Group(Source, {"ID"}, {{"All", each Table.FromColumns(Table.ToColumns(_) & {{[ID]{0}?}}, Value.Type(_ & #table(type table[Unique ID=Int64.Type],{}))), type table}}),
Combined = Table.Combine(GroupedRows[All])
in
Combined
lovely question, use this formula to reach this result
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each if List.Contains(List.FirstN(Source[ID],[Index]),[ID]) then "" else [ID])
in
#"Added Custom"
lovely question, use this formula to reach this result
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each if List.Contains(List.FirstN(Source[ID],[Index]),[ID]) then "" else [ID])
in
#"Added Custom"
Hi @nathan_kul, different approach here:
I've used @Anonymous sample data.
Output
let
Source = Table.FromRecords({[ID = 1], [ID = 2], [ID = 2], [ID = 3], [ID = 3], [ID = 3]}),
GroupedRows = Table.Group(Source, {"ID"}, {{"All", each Table.FromColumns(Table.ToColumns(_) & {{[ID]{0}?}}, Value.Type(_ & #table(type table[Unique ID=Int64.Type],{}))), type table}}),
Combined = Table.Combine(GroupedRows[All])
in
Combined
Hi @nathan_kul ,
Please refer to the following steps. You can adjust the Source step to match your actual data source.
let
Source = Table.FromRecords({[ID = 1], [ID = 2], [ID = 2], [ID = 3], [ID = 3], [ID = 3]}),
#"Grouped Rows" = Table.Group(Source, {"ID"}, {{"Data", each Table.AddIndexColumn(_, "Index", 0, 1, Int64.Type)}}),
#"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Index"}, {"Index"}),
#"Added Custom" = Table.AddColumn(#"Expanded Data", "ID2", each if [Index]=0 then [ID] else null),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
#"Removed Columns"
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum