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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Jo_Chrq
Helper I
Helper I

Yearly comparison with month to date

Hi,

I struggle with a graph, I can't seem to find the solution on the forum.

 

I have graph showing monthly revenues per year :

Jo_Chrq_0-1631785882735.png

For the current month (ie. September), I would like to have the month to date revenue, but same date range for that month in previous years:

1 - 15 sept 2021 vs. 1 - 15 sept 2020 vs. 1 - 15 sept 2019 etc.

with date range automatically growing every day.

 

Any ideas?

Many thanks

Jo

1 ACCEPTED SOLUTION

@Jo_Chrq I did have an error in that formula:

Measure = 
  VAR __MaxDate = MAX('Dates'[Date]) //if this is 9/15/2021 in filter context
  VAR __MinDate = MIN('Dates'[Date]) //if this is 9/1/2021 in filter context
  VAR __PreviousYearMax = DATE(YEAR(__MaxDate)-1,MONTH(__MaxDate),DAY(__MaxDate)) //this is 9/15/2020 because the DAY will be 15, month is 9 and year is 2021 - 1
  VAR __PreviousYearMin = DATE(YEAR(__MinDate)-1,MONTH(__MinDate),DAY(__MinDate)) //this is 9/1/2020 because DAY is 1, month is 9 and year is 2021 - 1
RETURN
  SUMX(FILTER('Table',[Date]<=__PreviousYearMax && [Date]>=__PreviousYearMin),[Value])

 


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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@Jo_Chrq You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

In your case, I imagine something like:

Measure = 
  VAR __MaxDate = MAX('Dates'[Date])
  VAR __MinDate = MIN('Dates'[Date])
  VAR __PreviousYearMax = DATE(YEAR(__MaxDate)-1,MONTH(__MaxDate),DAY(__MaxDate))
  VAR __PreviousYearMin = DATE(YEAR(__MinDate)-1,MONTH(__MinDate),DAY(__MinDate))
RETURN
  SUMX(FILTER('Table',[Date]<=__MaxDate && [Date]>=__MinDate),[Value])

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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg thanks for your reply.

Unfortunately this doesn't work for (unless I'm missing something).

I do get the revenue for 1 - 15 Sept 2021 but this keeps the full month's data for preivous year (1 - 30 sept 2020)

@Jo_Chrq I did have an error in that formula:

Measure = 
  VAR __MaxDate = MAX('Dates'[Date]) //if this is 9/15/2021 in filter context
  VAR __MinDate = MIN('Dates'[Date]) //if this is 9/1/2021 in filter context
  VAR __PreviousYearMax = DATE(YEAR(__MaxDate)-1,MONTH(__MaxDate),DAY(__MaxDate)) //this is 9/15/2020 because the DAY will be 15, month is 9 and year is 2021 - 1
  VAR __PreviousYearMin = DATE(YEAR(__MinDate)-1,MONTH(__MinDate),DAY(__MinDate)) //this is 9/1/2020 because DAY is 1, month is 9 and year is 2021 - 1
RETURN
  SUMX(FILTER('Table',[Date]<=__PreviousYearMax && [Date]>=__PreviousYearMin),[Value])

 


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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.