Forum Discussion
Creating a new table from 2 others with a calculation
- Anonymous6 years ago
PatrickByGecko - You could create the following Calculated Table in DAX:
New = ADDCOLUMNS(Dates, "Nbr Male", COUNTROWS( FILTER( ALL(Workers), Workers[DateEntry] <= Dates[Date] && Workers[Sex] = "male" ) ), "Nbr Female", COUNTROWS( FILTER( ALL(Workers), Workers[DateEntry] <= Dates[Date] && Workers[Sex] = "female" ) ) )
PatrickByGecko - Try this one:
New 2 =
var _CalendarBegin = DATE(2019,1,1)
return ADDCOLUMNS(Dates,
"Nbr Male",
COUNTROWS(
FILTER(
ALL(Workers),
Workers[Sex] = "male" && (Workers[DateEntry] = Dates[Date] || (Dates[Date] = _CalendarBegin && Workers[DateEntry] < _CalendarBegin))
)
),
"Nbr Female",
COUNTROWS(
FILTER(
ALL(Workers),
Workers[Sex] = "female" && (Workers[DateEntry] = Dates[Date] || (Dates[Date] = _CalendarBegin && Workers[DateEntry] < _CalendarBegin))
)
)
)As you can see, with this script I loose the first range of Dates (1/1/2019) and all counters are empty (have a look at the very bottom of this screen).
- Anonymous6 years agoNot applicable
PatrickByGecko - I think there is a problem with "ors" (||) and "ands" (&&). Please use the parentheses as they were in the measure I sent. Mixing "Ands" and "Ors" can produce unpredictable/problmatic logic.
The logic is:
Category = "<Some Category>"
AND
(
Worker Date = Date
OR
(
Worker Date is Prior to Begin Date
AND
Date = Begin Date
)
)
- PatrickByGecko6 years ago
Helper V
I did put some "(" the best I can, but only the first row is completed I mean when date=_DateBegin.
- Anonymous6 years agoNot applicable
PatrickByGecko - Can you please check some particular dates that are known to have data and let me know whether they have data for the Measure?