Forum Discussion
GROUPBY with ALLEXCEPT filter in measure
Is there a way to use ALLEXCEPT in filtering the input to a GROUPBY Table measure?
I am creating a dashboard to show comparitive figures between the latest report month and selected month that the user selects via slicer and can subsiquently be sliced by Cycle. The data shows Orders and Order Values but duplicates both of these fields as also contains Contacts for each order.
| Order No | Order Value | Canc. Date Fix | Cycle No. Band | Contact Date | Contact Description |
| 708456 | 8.06 | 04/06/2019 | 1-3 | 01/06/2019 | AB1 |
| 708456 | 8.06 | 04/06/2019 | 1-3 | 03/06/2019 | AB2 |
| 849576 | 4.5 | 05/04/2019 | 4-7 | 20/03/2019 | AB5 |
| 519543 | 5.1 | 19/05/2019 | <1 | 19/05/2019 | AB1 |
| 8416791 | 8.1 | 20/05/2019 | 1-3 | 15/05/2019 | AB4 |
I have successfully created a measure to show the Distinct No. of Orders Cancelled in the latest month as follows.
Latest Month Cancellations =
CALCULATE(
DISTINCTCOUNT('All Clients'[Order No.]),
filter(
ALLEXCEPT(
'All Clients',
'All Clients'[Cycle No. Band],
),
format(('All Clients'[Canc. Date Fix]),"MMM")=[Latest Report Month]
)
)However when applying this logic to a GroupBy so that the Order Value can also be sliced, the result is always the whole Month Value for latest month and will not pickup the cycle No. slicer. - It is as though it is treating the ALLEXCEPT as an ALL function. code attempt as follows
Latest Month Order Value Fix = var OrdValTBL2 =
GROUPBY(
FILTER(
ALLEXCEPT(
'All Clients',
'All Clients'[Cycle No. Band],
),
format('All Clients'[Canc. Date Fix],"MMM")=[Latest Report Month])
,
'All Clients'[Order No.],
"Min Ord Val",
minx(CURRENTGROUP(),[Order Value])
)
return
sumx(OrdValTBL2,[Min Ord Val])I don't know if I am asking the impossible or if my approach is incorrect but any assistance would be greatly received.
NB
The Groupby approach does produce correct figures without the Latest Month filter issue...
Order Value Fix = var OrdValTBL = GROUPBY( 'All Clients', 'All Clients'[Order No.], "Min Ord Val", minx(CURRENTGROUP(),[Order Value]) ) return sumx(OrdValTBL,[Min Ord Val])
8 Replies
- DouweMeer
Impactful Individual
If you're trying to show the data from previous month, try:
calculate ( [expression] , previousmonth ( [dates] ) )
Much much easier.
- DevDelwynFrequent Visitor
Hi DouweMeer,
That will not give me the correct results as the data contains duplicates i.e. in the example data above order 708456 is listed twice with its order value of 8.06 - so your suggestion would calculate its order value as 16.12.
The Groupby with ...
minx(CURRENTGROUP(),[Order Value])
..gives me the distinct order value for each order but I am not able to slice further in its current form.
- DouweMeer
Impactful Individual
If you're looking only for the distinct PO numbers as of previous month, you could do something like
VAR a1 = distinct ( selectcolumn ( 'table' , "column" , 'table'[column] )
to create your own table reference with distinct values. Then use that as a table to make your calculations on it.
RETURN
countx ( a1 , [column] )
There are multiple expressions that allow you to use a table reference instead of an actual table as context. You can even get string values from such a table if you ever need it.