Forum Discussion
Filter by Max Date or Selected Date
- Anonymous9 years ago
Hi inescastelhano,
You can try to use below formula if it suitable for your requirement:Result = IF(COUNTROWS('Calendar')<>COUNTROWS(ALL('Calendar')),//check all selected or not select "Distinct Count: "&CALCULATE(DISTINCTCOUNT('Link'[Employee]),VALUES('Calendar'[Date])), "Last Month: "&MONTH(LASTDATE('Calendar'[Date])))Notice: you should ensure these tables contains relationship and the cross filter direction is setting to 'both'.
Regards,
Xiaoxin Sheng
you might have to use an if statement but maybe lastdate will work for you?
- inescastelhano9 years agoFrequent Visitor
Hi vanessafvg, however LASTDATE receives and returns an argument of type DATE and there is no way for me to know the MonthID for that date, since I have several years. I can understand how to use the LASTDATE to get the last month with
Month(LASTDATE('Calendar'[Id_Date]))
, but not how to use it for filtering in CALCULATE expression.
Thank you,
Inês
- vanessafvg9 years ago
Community Champion
like this maybe?Headcount = calculate(DISTINCTCOUNT(Link[Employee Nr]), SOMETHING TO BE FILTERED BY DATE)
Headcount =
CALCULATE (
DISTINCTCOUNT ( Link[Employee Nr] ),
FILTER (
datetable,
MONTH ( 'Calendar'[Id_Date] ) = MONTH ( LASTDATE ( 'Calendar'[Id_Date] ) )
)
)unless i misunderstand what you asking for- inescastelhano9 years agoFrequent Visitor
No you didn't misunderstand. I think you're getting to the point of my question.
However, I know this is not working properly because my headcount for the actual month is 20K and the result of this expression is 37K.
Moreover, I figured out this is responding to the selection, but it's not correctly calculating for the 'default' month, I also added the year to the expression to ensure it is calculating for the right year, but it's still not working.
test3 = CALCULATE(
DISTINCTCOUNT ( Link[Employee Nr] ),
FILTER ('Calendar',MONTH('Calendar'[Id_Date]) = MONTH(LASTDATE ( 'Calendar'[Id_Date]))),
FILTER('Calendar', YEAR('Calendar'[Id_Date]) = YEAR(LASTDATE ( 'Calendar'[Id_Date])))
)
- inescastelhano9 years agoFrequent Visitor
Hi vanessafvg, moreover I get an error saying "A function LASTDATE has been used in a True/False expression that is used as a table filter expression. This is not allowed."
Thank you