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
CH_MJR79
Helper II
Helper II

Comparing data same period last year

Hi all,

 

I have table that contains lines posted to a timesheet each day for certain categories.

I've created a measure that calculates the total 'Actual Units' for the year to date, but I also need to create a measure that shows the data as at the same period compared to last year.

The measure I have created so far that shows the year to date total is below

SickDaysYTD = CALCULATE(SUM(SickDays[Actual_Units]),DATESYTD(SickDays[Date],"11-30"))

(the "11-30" date is the from date, which is the end of our fiscal year)

I was wondering if anyone could suggest a way of creating a measure to calculate the total Actual Units for the same period one year ago.

I would need the measure to take into account the end of the fiscal year, so for example, we are at 2nd November now, so the comparative measure would need to select data from 30th November 2020 to 2nd November 2021.

 

I've put some sample data below. Thanks in advance.

 

DescriptionDateActual_Units
Training25/10/202215.5
Training13/10/202275
Training12/10/202275
Training11/10/2022150
Training10/10/202275
Training07/10/202225
Training03/10/202275
Training28/09/2022 75
Training26/09/2022150
Training23/09/202265
Training20/09/2022 75
Training15/09/2022 20
Training12/09/202275
Training07/09/2022 75
Training06/09/202275
Training01/09/2022 30
Training24/08/2022 150
Training23/08/2022 35
Training19/08/2022 65
Training18/08/2022 75
Training17/08/2022 150
Training16/08/2022 150
1 ACCEPTED SOLUTION

Hi @CH_MJR79 ,

According to your description, I modify the formula:

SickDaysYTD_Pre =
VAR _Pre =
    DATEADD ( 'SickDays'[Date], -12, MONTH )
VAR _PreToday =
    DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
RETURN
    CALCULATE (
        SUM ( SickDays[Actual_Units] ),
        DATESYTD ( _Pre, "11-30" ),
        'SickDays'[Date] <= _PreToday
    )

Get the correct result in my sample.

vkalyjmsft_0-1667972769180.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
CH_MJR79
Helper II
Helper II

Many thanks @v-yanjiang-msft. I actually ended up doing this in a slightly different way, by modifying my underlying SQL query to get the data for the period I needed. But will try out your suggestion above.

Please check my solution 
Last Year = CALCULATE((Sum(Sheet1[Amount])),DATEADD(Sheet1[Date],-1,YEAR))

 

Last Year.png

v-yanjiang-msft
Community Support
Community Support

Hi @CH_MJR79 ,

According to your description, here's my solution, create a measure.

SickDaysYTD_Pre =
VAR _Pre =
    DATEADD ( 'SickDays'[Date], -12, MONTH )
RETURN
    CALCULATE ( SUM ( SickDays[Actual_Units] ), DATESYTD ( _Pre, "11-30" ) )

Get the correct result in my sample:

vkalyjmsft_1-1667454793509.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi @v-yanjiang-msft 

I've done some more work on this and I can see what is happening - the YTD_Pre formula you kindly provided seems be adding up the total for the whole of the previous fiscal year (i.e. 1st November 2020 to 30th November 2021), rather than calculating the total as at the date that the report is being ran, i.e. if I run the report today (3rd November 2022) then it should show the previous year total as at 3rd November 2021.

 

The forum doesn't allow me to attach a copy of the Power BI file I'm playing with but I have attached screenshot.

Capture.PNG

 

Hi @CH_MJR79 ,

According to your description, I modify the formula:

SickDaysYTD_Pre =
VAR _Pre =
    DATEADD ( 'SickDays'[Date], -12, MONTH )
VAR _PreToday =
    DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
RETURN
    CALCULATE (
        SUM ( SickDays[Actual_Units] ),
        DATESYTD ( _Pre, "11-30" ),
        'SickDays'[Date] <= _PreToday
    )

Get the correct result in my sample.

vkalyjmsft_0-1667972769180.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.

Top Solution Authors