Forum Discussion
HarryPotter115
2 years agoNew Member
Marke duplicated base on other column
HI, Please help me in Power Querry. This is sample data The Data has two column A and B, I wand to add column C with criterial below: 1. It is 1 if value in A column is unique 2. It is 2 ...
jgeddes
Super User
2 years agoHere is an example of one way to accomplish this...
let
Source =
Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"i45WclTSUTJSitWBsIzRWE5AlikayxnIMgSzXIAsEzgLKBsLAA==",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Criteria1 = _t, Criteria2 = _t]
),
#"Changed Type" =
Table.TransformColumnTypes(
Source,
{{"Criteria1", type text}, {"Criteria2", type text}}
),
Custom1 =
Table.AddColumn(
#"Changed Type",
"_mark",
each
if List.Count(Table.SelectRows(#"Changed Type", (x)=> x[Criteria1] = [Criteria1])[Criteria1]) = 1
then 1
else if List.Count(Table.SelectRows(#"Changed Type", (x)=> x[Criteria1] = [Criteria1])[Criteria1]) = 2 and List.Count(Table.SelectRows(#"Changed Type", (x)=> x[Criteria2] = [Criteria2] and x[Criteria1] = [Criteria1])[Criteria2]) = 2
then 2
else if List.Count(Table.SelectRows(#"Changed Type", (x)=> x[Criteria1] = [Criteria1])[Criteria1]) = 2 and List.Count(Table.SelectRows(#"Changed Type", (x)=> x[Criteria2] = [Criteria2] and x[Criteria1] = [Criteria1])[Criteria2]) <> 2
then 8
else if List.Count(Table.SelectRows(#"Changed Type", (x)=> x[Criteria1] = [Criteria1])[Criteria1]) > 2
then 3
else 9
)
in
Custom1