Forum Discussion
I need help creating a YTD count measure
I can't believe I'm stuck on such a simple task. I have a table that contains data from 2018 to now. Basically, I need a measure to count the total number of rows for 2018.
I used this measure and it only gave me the count for 2019. How do I find 2018's acount?
2019 YTD Count = TOTALYTD(COUNT('Escalation Log'[Date Received]), 'Escalation Log'[Date Received])
powerbi92614 , give this one a try. It forces the date range to be the full prior year.
PY YTD = VAR MaxDate = MAX ( 'Escalation Log'[Date Received] ) VAR PYStart = DATE ( YEAR ( MaxDate ) -1, 1, 1 ) VAR PYEnd = DATE ( YEAR ( MaxDate ) -1, 12, 31 ) RETURN CALCULATE ( COUNT ( 'Escalation Log'[Date Received] ), DATESBETWEEN ( 'Escalation Log'[Date Received], PYStart, PYEnd ) )
4 Replies
- jdbuchanan71
Super User
Hello powerbi92614
You can shift your date range back a year like so.
PY YTD = TOTALYTD(COUNT('Escalation Log'[Date Received]), SAMEPERIODLASTYEAR('Escalation Log'[Date Received]))- powerbi92614New Member
jdbuchanan71 Hi there - thank you so much for your response. This is great, except it's only giving me the count from January 2018 - August 2018. Any suggestions on getting the full year count? Thanks again!
- jdbuchanan71
Super User
powerbi92614 , give this one a try. It forces the date range to be the full prior year.
PY YTD = VAR MaxDate = MAX ( 'Escalation Log'[Date Received] ) VAR PYStart = DATE ( YEAR ( MaxDate ) -1, 1, 1 ) VAR PYEnd = DATE ( YEAR ( MaxDate ) -1, 12, 31 ) RETURN CALCULATE ( COUNT ( 'Escalation Log'[Date Received] ), DATESBETWEEN ( 'Escalation Log'[Date Received], PYStart, PYEnd ) )