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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Karenh
New Member

How setup a last year with the same month to the current year

Hi Community 

 

I need to compare the current year versus the last year, but my current year has only information from (Jan23 to Jul-23) qnd with this if I try to compare with the last year that hsa 12 months (Jan22 to Dec22) the comparission is wrong. so, Any idea how can I filter the last year according the period that I have in current year?

5 REPLIES 5
vanessafvg
Super User
Super User

please provide some sample data in text form with an example of your expected result.





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Thanks, find enclosed the file with the example. 

Karenh_0-1698438442842.png

 

sorry I need text data, can you copy and paste it in

 

my internet was hanging and pushed accept as solution, apologies will try to remove it but can you please copy and past the text?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




here you go 

DATA 2022                      DATA 2023
Jan-22 1,000.00              Jan-23  5,000.00
Feb-22 2,000.00             Feb-23  3,500.00
Mar-22 1,000.00             Mar-23  1,000.00
Apr-22 2,000.00              Apr-23  5,000.00
May-22 1,000.00            May-23  3,500.00
Jun-22 1,400.00               Jun-23  1,000.00
Jul-22 1,400.00
Aug-22 1,400.00
Sep-22 1,400.00
Oct-22 1,400.00
Nov-22 1,400.00
Dec-22 1,400.00
Total 16,800.00                  19,000.00

 

URRENT RESULT
LAST YEAR       CURRENT YEAR
 16,800.00        19,000.00
 
EXPECTED RESULT
LAST YEAR CURRENT YEAR
 8,400.00            19,000.00 COMPARE THE SAME MONTHS FROM JAN TO JUN
 
Thanks

I used this example from SQLBI

https://www.sqlbi.com/articles/previous-year-up-to-a-certain-date/

 

You need to create a flag to assess when there is a value from the current year for previous year and then use that in your measure, and then it will only show you when have a value in both years.  

 

IsPast =
VAR CurrDate = MAX ( data[Date])
VAR LastSDatePY = EDATE ( CurrDate, -12 )
RETURN
    'Date'[Date] <= LastSDatePY
 
Previous Year =
CALCULATE (
    [total amount],
    SAMEPERIODLASTYEAR ( 'Date'[Date] ),
    'Date'[IsPast] = TRUE
)

 

 

vanessafvg_0-1698603509689.png

 

see file attached.  

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.