Forum Discussion
Ignore grouping if value is found
I want to write a DAX which count the rows based on the grouping columns 'id' and 'date', but at the same time want to ignore the grouping count if the value contains x.
below is the expected result.
id date value a 19-Jan x a 19-Jan y c 20-Jan y d 20-Jan x e 21-Jan y e 21-Jan y Result c 20-Jan y e 21-Jan y countrow =2
14 Replies
- AnonymousNot applicable
Did this in PQ and DAX, but I think PQ was a little easier and probably performs better, but a preference.
So for PQ:
- Load data in PQ
- Duplicate the query (I named as Grouped Table)
- Grouped the Rows by ID and Date
- Add a column to the table to look for "X" in any of the rows of the grouped tables
- if so, returns true, if not, returns false
- remove duplicates
- Go back to original query ( what i called the Final Table)
- Merge the final table with the Grouped table
- Expand the "Has x?" column
You get a final table that looks like:
Then a simple distinct count measure:
Dist Count = CALCULATE( DISTINCTCOUNT('Final Table'[id ]), 'Final Table'[Has x?] = FALSE)and you get this:
and here's the DAX way ( didnt fully troubleshoot this one, so there may be an issue or two)
Here's the pbix:
- joepath
Helper II
Thanks for the reply Nick_M, will try these methods on my fact table and let you know if this works, but will it be good if I create a group table on a big fact table?
- AnonymousNot applicable
the go to answer is , " it depends". The size of the table really isn't the issue, it's the cardinality of it. And if you are getting this data from a relational database you can use query folding to push the heavy lifting to the database.
If you do this in DAX you will probably need to use summarize or something simliar, which produces a table in memory. Tables in memory do not take advantage of Vertipaq so performnace might suffer, which can make it a slow experience for the end user.
Physical tables are only updated at refresh time, so given the choice (along with query folding if possible) I'd always go the way of PQ when possible. Give it shot on your side and see what happens. :smileyhappy: