Forum Discussion
Union filter in Power Query or DAX
- Anonymous7 years ago
What about something like this?
So Items 1 and 6 have all ABC, but item 3 does not since ABC happened in one row, but if that needs to be accounted for can change the code easily.
ALL ABC Check = var __CurrentID= Table1[Item] RETURN Var __NewColumn= CALCULATE( CONCATENATEX( 'Table1', 'Table1'[Added by]), FILTER( 'Table1', Table1[Item] = __CurrentID ) ) RETURN IF( AND( LEN(Table1[Added by]) =1, SEARCH("A",__NewColumn,,0)+SEARCH("B",__NewColumn,,0)+SEARCH("c",__NewColumn,,0) >= 3 ), "ALL ABC", "Missing" )
Thanks, however I'm afraid that this is not a solution I'm looking for.
This is a full code, which does exactly what I want.
But I still want to do it in DAX, but still can't figure out how.
I think that DAX solution would be much more elegant.
let
Source = Table1,
#"Filtered Rows" = Table.SelectRows(Source, each ([Added by] = "A" or [Added by] = "B" or [Added by] = "C")),
#"Kept Duplicates" = let columnNames = {"Item"}, addCount = Table.Group(#"Filtered Rows", columnNames, {{"Count", Table.RowCount, type number}}), selectDuplicates = Table.SelectRows(addCount, each [Count] > 1), removeCount = Table.RemoveColumns(selectDuplicates, "Count") in Table.Join(#"Filtered Rows", columnNames, removeCount, columnNames, JoinKind.Inner)
in
#"Kept Duplicates"
This is Excel file
https://www.dropbox.com/s/lyi4sfhz9pihwzz/multiple_filter_union_set_analysis.xlsx?dl=0
This is Power BI link with Power Query solution
https://www.dropbox.com/s/qgiz3qxbeq6d74q/combined%20complex%20filter.pbix?dl=0
What about something like this?
So Items 1 and 6 have all ABC, but item 3 does not since ABC happened in one row, but if that needs to be accounted for can change the code easily.
ALL ABC Check =
var __CurrentID= Table1[Item]
RETURN
Var __NewColumn=
CALCULATE(
CONCATENATEX(
'Table1',
'Table1'[Added by]),
FILTER(
'Table1',
Table1[Item] = __CurrentID
)
)
RETURN
IF(
AND(
LEN(Table1[Added by]) =1,
SEARCH("A",__NewColumn,,0)+SEARCH("B",__NewColumn,,0)+SEARCH("c",__NewColumn,,0) >= 3
),
"ALL ABC",
"Missing"
)- vyacheslavg7 years agoHelper II
I will not pretend that I fully understand this DAX, but it works perfectly and I can easily modify it for production cases.
This is good, since I do not need to reload rather big sources and filter it in a fraction of second, unlike my Power Query or Pandas solutions.
Thanks!