Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
I am trying to test a simple function that replace duplicated values with null in Name column:
let
Source = Excel.CurrentWorkbook(){[Name="TB_source"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Amount", Int64.Type}}),
RemoveDups = (aTable as table, colNames as text) =>
let
dupsNull = List.Generate(
()=>[v=aTable[colNames]{0}, idx=0],
each [idx]<Table.RowCount(aTable),
each [v=if List.PositionOf(aTable[colNames],aTable[colNames]{[idx]+1},Occurrence.First) = [idx]+1
then aTable[colNames]{[idx]+1} else null, idx=[idx]+1],each [v])
in
dupsNull,
#"listUnique" = RemoveDups(#"Changed Type", "Name")
in
#"listUnique"
A get a List but with errors:
when I click on the error I am getting the following information:
If I click on Go to Error I am getting the following:
I was trying to define the ColNames input argument as a list but I was not able to make it work, I am getting erros of with different information.
I was able to make work a similar peace of code, but without invoking a function as follow:
let
Source = Excel.CurrentWorkbook(){[Name="TB_source"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Amount", Int64.Type}}),
dupsNull = List.Generate(
()=>[v=#"Changed Type"[Name]{0}, idx=0],
each [idx]<Table.RowCount(#"Changed Type"),
each [v=if List.PositionOf(#"Changed Type"[Name],#"Changed Type"[Name]{[idx]+1},Occurrence.First) = [idx]+1
then #"Changed Type"[Name]{[idx]+1} else null, idx=[idx]+1],
each [v])
in
dupsNull
and I am getting the expected result for the list:
Any help is appreciated, please take into account I am new to Power Query and M.
Thanks,
David
Solved! Go to Solution.
try to change all "aTable[colNames]" to "Table.Column(aTable,colNames)"
or try this code
fx=(lst as list)=>List.Accumulate(lst,{},(x,y)=> x&{ if List.Contains(x,y) then null else y})
Thanks @wdx223_Daniel it tested both options and both of them work. Thanks! Here the source code updated for further reference. In block comment the first option (larger):
let
Source = Excel.CurrentWorkbook(){[Name="TB_source"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Amount", Int64.Type}}),
RemoveDups = (lst as list)=>List.Accumulate(lst,{},(x,y)=> x&{ if List.Contains(x,y) then null else y}),
/*
RemoveDups = (aTable as table, colNames as text) =>
let
dupsNull = List.Generate(
()=>[v=Table.Column(aTable,colNames){0}, idx=0],
each [idx]<Table.RowCount(aTable),
each [v=if List.PositionOf(Table.Column(aTable,colNames),
Table.Column(aTable,colNames){[idx]+1},Occurrence.First) = [idx]+1
then Table.Column(aTable,colNames){[idx]+1} else null, idx=[idx]+1],each [v])
in
dupsNull,
#"runiqueList" = RemoveDups(#"Changed Type", "Name")
*/
#"runiqueList" = RemoveDups(Table.Column(#"Changed Type","Name"))
in
#"runiqueList"
Thanks again
try to change all "aTable[colNames]" to "Table.Column(aTable,colNames)"
or try this code
fx=(lst as list)=>List.Accumulate(lst,{},(x,y)=> x&{ if List.Contains(x,y) then null else y})
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 9 | |
| 8 | |
| 7 | |
| 5 | |
| 5 |