Forum Discussion

powerbi92614's avatar
powerbi92614
New Member
7 years ago
Solved

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])

  • jdbuchanan71's avatar
    jdbuchanan71
    7 years ago

    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

  • 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]))
    • powerbi92614's avatar
      powerbi92614
      New 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's avatar
        jdbuchanan71
        Icon for Super User rankSuper 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 )
        )