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
Peter_23
Post Patron
Post Patron

Comparing two periods

Hi Power Bi users, I would like a measure to compare two periods at least, e.g. Feb23 vs Feb22,  Apr23 vs Apr22, but sometimes it could be Feb23 vs Feb20, in case there is not data in 22,21..  

so I know there is: SAMEPERIODLASTYEAR function; but It's year based, so my requirements is over months, is there workaround for this?

 

thanks in advance.

4 REPLIES 4
Peter_23
Post Patron
Post Patron

thanks guys, the aproach of situation is more likely to @Anonymous , so you can only select one value e.g. Feb23 and the previuos value should be Feb22,  (automatically). I'll work with your proposal. I'm working with calculate and offset filter function or windows command Offset  , do you experience with these functions?

Ashish_Mathur
Super User
Super User

Hi,

Please share some data to work with and show the expected result.  Share data in a format that can be pasted in an MS Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thanks for the reply from danextian , please allow me to provide another insight: 
Hi  @Peter_23 ,

I created some data:

vyangliumsft_0-1725331562405.png

 

Here are the steps you can follow:

1. Create measure.

Measure =
var _minmonth=MINX(ALLSELECTED('Table'),[MonthYear])
var _maxmonth=MAXX(ALLSELECTED('Table'),[MonthYear])
var _minmonthdate=
MINX(FILTER(ALL('Table'),'Table'[MonthYear]=_minmonth),[Date]) //2022.2.1
var _maxmonthdate=
MAXX(FILTER(ALL('Table'),'Table'[MonthYear]=_maxmonth),[Date]) //2023.2.3
var _maxmonthnotblank=
MAXX(
    FILTER(ALL('Table'),'Table'[Date]<=_maxmonthdate&&[Amount]<>BLANK()&&MONTH([Date])=MONTH(_maxmonthdate)),[MonthYear]) // Feb23
var _date=
MINX(FILTER(ALL('Table'),'Table'[MonthYear]=_maxmonthnotblank),[Date])
var _minmonthnotblank=
MAXX(
    FILTER(ALL('Table'),'Table'[Date]<_date&&[Amount]<>BLANK()&&MONTH([Date])=MONTH(_minmonthdate)),[MonthYear]) // Feb23
return
    SUMX(FILTER(ALL('Table'),'Table'[MonthYear]=_maxmonth),[Amount]) - SUMX(FILTER(ALL('Table'),'Table'[MonthYear]=_minmonthnotblank),[Amount])

2. Result:

vyangliumsft_1-1725331562406.png

 

 

Best Regards,

Liu Yang

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

danextian
Super User
Super User

Hi @Peter_23 ,

If you want it hardcoded, you can try something like this:

January 2023 = 
CALCULATE (
    [Total Revenue],
    FILTER (
        ALL ( Dates ),
        MONTH ( Dates[Date] ) = 1
            && YEAR ( Dates[Date] ) = 2023
    )
)

This approach is very manual and require a lot of measures for periods that you want to compare.

Alternatively, I would use a two-slicer approach - for periods being compared. The second slicer is coming from a disconnected table which doesn't have  relationship to your fact table. Either approach will require a separate dates table.

 

In the sample pbix, there are only two years of data but should work for more years.

danextian_0-1725168943072.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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
Top Kudoed Authors