Forum Discussion
DAX calculated column only working when variables used
- 6 years ago
Well, I have solved the problem myself just a short time after posting!
In my first attempt at the calculated column, I used [StoreName], but the problem is this unqualified column name is ambiguous and could refer to either Roster[StoreName] or RosterList[StoreName]. I was assuming that because this was in a calculated column expression, it would default to the "current" table (which I guess is true when it's assigned to a VAR outside of the FILTER function) ... i.e. the implicit row context of the calculation. This seems to be wrong.
The simple fix is to qualify the column reference (also for [Date] though it's not ambiguous, but for clarity it should be qualified!)
Rostered Employee = CONCATENATEX( SELECTCOLUMNS( FILTER(Roster, // Wrong ... [StoreName] = Roster[StoreName] // Right ... RosterList[StoreName] = Roster[StoreName] && RosterList[Date] >= Roster[StartDate] && RosterList[Date] <= Roster[EndDate] ) , "Employee" , [Employee] ), [Employee], ", " )This is now giving the correct results! Thanks for anyone who viewed it so far, and hopefully this may help others who make the same mistake that I did 🙂
Well, I have solved the problem myself just a short time after posting!
In my first attempt at the calculated column, I used [StoreName], but the problem is this unqualified column name is ambiguous and could refer to either Roster[StoreName] or RosterList[StoreName]. I was assuming that because this was in a calculated column expression, it would default to the "current" table (which I guess is true when it's assigned to a VAR outside of the FILTER function) ... i.e. the implicit row context of the calculation. This seems to be wrong.
The simple fix is to qualify the column reference (also for [Date] though it's not ambiguous, but for clarity it should be qualified!)
Rostered Employee =
CONCATENATEX(
SELECTCOLUMNS(
FILTER(Roster,
// Wrong ... [StoreName] = Roster[StoreName]
// Right ...
RosterList[StoreName] = Roster[StoreName]
&& RosterList[Date] >= Roster[StartDate]
&& RosterList[Date] <= Roster[EndDate]
)
, "Employee"
, [Employee]
),
[Employee],
", "
)
This is now giving the correct results! Thanks for anyone who viewed it so far, and hopefully this may help others who make the same mistake that I did 🙂