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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
latimert
Regular Visitor

Similar period with variable year interval

Hello,

 

I'm looking for a way to compare current year sales results with results from Mar-19 to Feb-20.

We use this to measure against impacts of COVID etc and we consider Mar-19 to Feb-20 our pre-COVID period where COVID hadn't affected the business significantly.

 

So I'd need a measure to compare sales from Mar-Dec this year with Mar-Dec 19, and Jan-Feb this year with Jan-Feb 20.

 

I believe the measure will look something like CALCULATE(SUM('Table1'[Actuals]), filter to compare with same period 2019 or 2020)

I've had a look into the PARALLELPERIOD function but I had trouble with using a variable for the interval argument.

 

Please let me know if this makes sense or if any further information is required.

Thanks in advance.

1 ACCEPTED SOLUTION

@latimert Well, you can try this:

Measure = 
  VAR __Start = MIN('Table'[Date])
  VAR __PreCOVIDStart = IF(MONTH(__Start) > 2, DATE(2019,MONTH(__Start),1), DATE(2020,MONTH(__Start),1) )
  VAR __PreCOVIDEnd = EOMONTH(__PreCOVIDStart,0)
  VAR __SalesPC = CALCULATE(SUM('Table'[Sales]),ALL('Table'),'Table'[Date]>= __PreCOVIDStart && [Date]<=__PreCOVIDEnd)
RETURN
  __SalesPC

Filtering ranges sucks and using CALCULATE is hit or miss depending on your visual configuration and whether or not you have a star schema as well as what cycle the moon happens to be in (generally works during a Waning Gibbous).

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

9 REPLIES 9
latimert
Regular Visitor

@Greg_Deckler 

 

Thanks for your reply.

Looks like it will work for overalll, but I'm wondering if it's possible to get this working to display something like the following:

YearMonthCurrent YearPre COVID
2022Aug $        1,000,000 $  2,000,000
2022Sep $        1,000,000 $  2,000,000
2022Oct $        1,000,000 $  2,000,000
2022Nov $        1,000,000 $  2,000,000
2022Dec $        1,000,000 $  2,000,000

 

Ideally, I'd like to see the results side by side as in the above table.

 

Appreciate your help.

@latimert Ah, by month, that would be:

 

 

Measure = 
  VAR __Start = MIN('Table'[Date])
  VAR __PreCOVIDStart = IF(MONTH(__Start) > 2, DATE(2019,MONTH(__Start),1), DATE(2020,MONTH(__Start),1) )
  VAR __PreCOVIDEnd = EOMONTH(__PreCOVIDStart,0)
  VAR __SalesPC = SUMX(FILTER(ALL('Table'),'Table'[Date]>= __PreCOVIDStart && [Date]<=__PreCOVIDEnd),[Sales])
RETURN
  __SalesPC

 

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler 

 

I get the following error when trying to add this measure:
A single value for column 'Date' in table 'GeneralLedger' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

My table is called GeneralLedger and my date column is called Date.

 

Thanks again for your help.

@latimert I think you are too quick! I realized I had an error in the formula and edited the post to correct it. Please check again after doing a page refresh. The offending piece of code was the first MONTH function in the PreCOVIDStart variable.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler May have been a bit too keen haha.

This measure works, however, it is extremely slow to load into a table of 6 rows (July - December). Is it expected that this would be slow? The dataset isn't huge and most measures are instantaneous. 

If you have any tips to make this faster, that would be much appreciated.

@latimert Well, you can try this:

Measure = 
  VAR __Start = MIN('Table'[Date])
  VAR __PreCOVIDStart = IF(MONTH(__Start) > 2, DATE(2019,MONTH(__Start),1), DATE(2020,MONTH(__Start),1) )
  VAR __PreCOVIDEnd = EOMONTH(__PreCOVIDStart,0)
  VAR __SalesPC = CALCULATE(SUM('Table'[Sales]),ALL('Table'),'Table'[Date]>= __PreCOVIDStart && [Date]<=__PreCOVIDEnd)
RETURN
  __SalesPC

Filtering ranges sucks and using CALCULATE is hit or miss depending on your visual configuration and whether or not you have a star schema as well as what cycle the moon happens to be in (generally works during a Waning Gibbous).

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

Will just tell the recipient to wait for the next waning gibbous then!

Jokes aside, calculate was significantly faster but I'll keep an eye out for any inconsistencies.

 

This has been very helpful. Thank you very much!

@latimert I've got a lot of problems with that function, but it's useful when it's useful! Festivus!



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@latimert Try something along the lines of:

Measure = 
  VAR __Year = YEAR(TODAY())
  VAR __PreCOVIDStart = DATE(2019,3,1)
  VAR __PreCOVIDEnd = DATE(2020,2,29)
  VAR __SalesTY = SUMX(FILTER(ALL('Table'),YEAR('Table'[Date]) = __Year),[Sales])
  VAR __SalesPC = SUMX(FILTER(ALL('Table'),'Table'[Date]>= __PreCOVIDStart && [Date]<=__PreCOVIDEnd),[Sales])
RETURN
  DIVIDE(__SalesTY,__SalesPC,0)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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