The function Allexcept is descriped quite the same both in "Definitive Guide to DAX":
"You can also specify one entire table instead of all the columns of a table that is part of the expanded table"(P430)
and on dax.guide:
"ALLEXCEPT removes filters from the expanded version of Sales, which includes all the tables that can be reached through a many-to-one relationship starting from Sales." https://www.sqlbi.com/articles/managing-all-functions-in-dax-all-allselected-allnoblankrow-allexcept/
And they all imply that Allexcept returns a table when not used as a top function in Calculate as filter arguments, just like what All() does, while in my practice it is something different:
Consider a single-table model like:
Name Datetime
John 2018/6/25
James 2018/7/7
Smith 2018/7/27
Smith 2018/11/21
Smith 2018/6/9
Mary 2019/1/31
Emily 2018/8/20
John 2018/6/9
Mary 2018/11/11
John 2018/8/21
with a related calendar using Calendarauto() with a calculated column:
YearMonth = FORMAT('Date'[Date],"yyyymm")
Now I want to know how many YearMonth does every Name correspond to, which should be like this:
Name MonthNum
John 2
James 1
Smith 3
Mary 2
Emily 1
With knowledge of expanded tables and Allexcept(and how context transition works), I used formula like this:
Wrong =
ADDCOLUMNS (
VALUES ( Data[Name] ),
"MonthNum", CALCULATE (
DISTINCTCOUNT ( 'Date'[YearMonth] ),
CALCULATETABLE ( ALLEXCEPT ( Data, Data[Name] ) )
)
)
The result turns out to be:
Name MonthNum
John 5
James 5
Smith 5
Mary 5
Emily 5
But I DO KNOW how to make it right, by adding "Data," after Calculatetable:
Correct =
ADDCOLUMNS (
VALUES ( Data[Name] ),
"MonthNum", CALCULATE (
DISTINCTCOUNT ( 'Date'[YearMonth] ),
CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[Name] ) )
)
)
Please explain the exact reason why Wrong Version does not behave as expected.