Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Data_Tim
New Member

Help with SAMEPERIODLASTYEAR

Happy new year all!

I am trying to use the SAMPERIODLASTYEAR function to count records from the previous year, so that I can compare them to the number of records for the current year (up until today's date). The problem I am running into is that the same day last year is counting records for the entire month, rather than just that corresponding day.

 

Data_Tim_0-1672829841453.png

 

I have a field in my Date table [check] which checks the day number of the year so future days in the same month can be filtered out.

 

Data_Tim_1-1672830162704.png

 

Any help to resolve this would be greatly appreciated. Many thanks

1 ACCEPTED SOLUTION

@Data_Tim 
Appologies for that. Yes you are right this was supposed to be CALCULATETABLE

Tickets LYTD =
CALCULATE (
    COUNT ( 'All Tickets'[sys_id] ),
    CALCULATETABLE (
        SAMEPERIODLASTYEAR ( DateTable[Date] ),
        DateTable[Check] = "True"
    )
)

Or 

Tickets LYTD =
CALCULATE (
    COUNT ( 'All Tickets'[sys_id] ),
    SAMEPERIODLASTYEAR ( DateTable[Date] ),
    FILTER ( ALL ( DateTable ), DateTable[Check] = "True" )
)

View solution in original post

4 REPLIES 4
Data_Tim
New Member

Thanks for getting back to me @tamerj1 .

Unfortunately that doesn't work as the Filter is expecting to evaluate DateTable[Date] not DateTable[Check]

Data_Tim_1-1672832814882.png

 

@Data_Tim 
Appologies for that. Yes you are right this was supposed to be CALCULATETABLE

Tickets LYTD =
CALCULATE (
    COUNT ( 'All Tickets'[sys_id] ),
    CALCULATETABLE (
        SAMEPERIODLASTYEAR ( DateTable[Date] ),
        DateTable[Check] = "True"
    )
)

Or 

Tickets LYTD =
CALCULATE (
    COUNT ( 'All Tickets'[sys_id] ),
    SAMEPERIODLASTYEAR ( DateTable[Date] ),
    FILTER ( ALL ( DateTable ), DateTable[Check] = "True" )
)

That's worked for me - thanks for your help @tamerj1 . Much appreciated

tamerj1
Super User
Super User

Hi @Data_Tim 
Please try

 

Tickets LYTD =
CALCULATE (
    COUNT ( 'All Tickets'[sys_id] ),
    FILTER ( SAMEPERIODLASTYEAR ( DateTable[Date] ), DateTable[Check] = "True" )
)

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.