Forum Discussion
Filtering data with conditions
I have a simple dataset
| Item | Item 2 | Order# |
| apple | pear | 1 |
| pear | apple | 1 |
| orange | banana | 2 |
| banana | orange | 2 |
| pear | orange | 3 |
| orange | pear | 3 |
| banana | orange | 3 |
| orange | banana | 3 |
| banana | pear | 3 |
| pear | banana | 3 |
as you can see, some lines are almost duplicated, so I need to get a different look of the table
I don't want to show row#2, it is enough to show row#1.
How to show the values I need?
| Item | Item 2 | Order# |
| apple | pear | 1 |
| orange | banana | 2 |
| pear | orange | 3 |
| banana | orange | 3 |
| banana | pear | 3 |
Someone can help?
Hello Anonymous
try like this,
M code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSiwoyElV0lEqSE0sAlKGSrE60TAOTA4imF+UmJcO4iYl5gEhkGEEFodz4QqMkA2BixqjmgKVNsZhhjEOO9HUo5gC5SCrjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Item = _t, #"Item 2" = _t, #"Order#" = _t]), ChangedType = Table.TransformColumnTypes(Source,{{"Item", type text}, {"Item 2", type text}, {"Order#", Int64.Type}}), RemovedDuplicates = Table.Distinct(ChangedType), AddedIndex = Table.AddIndexColumn(RemovedDuplicates, "Index", 1, 1), Join = Table.NestedJoin(AddedIndex, {"Item", "Item 2", "Order#"}, AddedIndex, {"Item 2", "Item", "Order#"}, "Dupes", JoinKind.LeftOuter), ExpandedDupes = Table.ExpandTableColumn(Join, "Dupes", {"Index"}, {"Index2"}), Distinct = Table.SelectRows(ExpandedDupes, each [Index] < [Index2]), RemovedOtherColumns = Table.SelectColumns(Distinct,{"Item", "Item 2", "Order#"}) in RemovedOtherColumnsHi Anonymous
I imagine it would be more convenient to do this in the query editor but if you want to do it in DAX, create a calculated table:
Table2 = VAR _ResTable = FILTER ( Table1; VAR _AuxTable = FILTER ( Table1; Table1[Order#] = EARLIER ( Table1[Order#] ) && Table1[Item] = EARLIER ( Table1[Item 2] ) && Table1[Item 2] = EARLIER ( Table1[Item] ) ) RETURN IF ( ( COUNTROWS ( _AuxTable ) <> 0 && Table1[Item] < Table1[Item 2] ) || COUNTROWS ( _AuxTable ) = 0; TRUE (); FALSE () ) ) RETURN _ResTable
8 Replies
- LivioLanzoSolution Sage
Hello Anonymous
try like this,
M code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSiwoyElV0lEqSE0sAlKGSrE60TAOTA4imF+UmJcO4iYl5gEhkGEEFodz4QqMkA2BixqjmgKVNsZhhjEOO9HUo5gC5SCrjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Item = _t, #"Item 2" = _t, #"Order#" = _t]), ChangedType = Table.TransformColumnTypes(Source,{{"Item", type text}, {"Item 2", type text}, {"Order#", Int64.Type}}), RemovedDuplicates = Table.Distinct(ChangedType), AddedIndex = Table.AddIndexColumn(RemovedDuplicates, "Index", 1, 1), Join = Table.NestedJoin(AddedIndex, {"Item", "Item 2", "Order#"}, AddedIndex, {"Item 2", "Item", "Order#"}, "Dupes", JoinKind.LeftOuter), ExpandedDupes = Table.ExpandTableColumn(Join, "Dupes", {"Index"}, {"Index2"}), Distinct = Table.SelectRows(ExpandedDupes, each [Index] < [Index2]), RemovedOtherColumns = Table.SelectColumns(Distinct,{"Item", "Item 2", "Order#"}) in RemovedOtherColumns- AlBCommunity Champion
Hi Anonymous
I imagine it would be more convenient to do this in the query editor but if you want to do it in DAX, create a calculated table:
Table2 = VAR _ResTable = FILTER ( Table1; VAR _AuxTable = FILTER ( Table1; Table1[Order#] = EARLIER ( Table1[Order#] ) && Table1[Item] = EARLIER ( Table1[Item 2] ) && Table1[Item 2] = EARLIER ( Table1[Item] ) ) RETURN IF ( ( COUNTROWS ( _AuxTable ) <> 0 && Table1[Item] < Table1[Item 2] ) || COUNTROWS ( _AuxTable ) = 0; TRUE (); FALSE () ) ) RETURN _ResTable- AnonymousNot applicable
Thanks, AlB,
It works!
You are right it would be better to make this in the query editor, but all I tried - did not work correctly.
Your DAX is too difficult but I try to understand and will use your solution.
Thanks a lot!
- AnonymousNot applicable
Hi LivioLanzo,
I checked your code and have to say - it doesn't work correctly. Or I made some mistakes...
Unfortunately, I have something like that:Item Item 2 Order# Index Index2 apple pear 1 1 2 pear apple 1 2 1 orange banana 2 3 4 banana orange 2 4 3 pear orange 3 5 6 orange pear 3 6 5 banana orange 3 7 8 orange banana 3 8 7 banana pear 3 9 10 pear banana 3 10 9 And the condition
Table.SelectRows(ExpandedDupes, each [Index] < [Index2]),
works correctly but without the result that I need.
Anyway, Thanks a lot for your help!- LivioLanzoSolution Sage
hI Anonymous
this is weird because when i run it on my side this is what I see as a result: