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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
dsmitha
Responsive Resident
Responsive Resident

Sales comparison - current day sales with sales on same day last month

Hi,

 

Request your guidance to overcome this issue

My Boss wants to compare the sales of current day ( say 03rd September 2022 ) with sales of same date of last month ( i.e. 03rd August 2022).  I got a slicer for selecting the date, so if we select 03rd September 2022 it will show the sales for today but how can we display sales for the same day on last month ( 03rd August 2022).  We have to consider months with 31 days / 30 days etc.

 

kindly advice

 

regards,

dsmitha 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@dsmitha Maybe: 

Measure = 
  VAR __Date = MAX('Table'[Date])
  VAR __EOLM = EOMONTH(__Date,-1)
  VAR __EOLMDay = DAY(__EOLM)
  VAR __Day = DAY(__Date)
  VAR __LMDay = IF(__EOLMDay < __Day, __Day, __EOLMDay)
  VAR __LMDate = DATE(YEAR(__EOLM),MONTH(__EOLM),__LMDay)
RETURN
  SUMX(FILTER(ALLSELECTED('Table',[Date]=__LMDate),[Sales])


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

If the date selected is July 31, 2022, then what would be the date of the "same day last month"?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Super User
Super User

@dsmitha Maybe: 

Measure = 
  VAR __Date = MAX('Table'[Date])
  VAR __EOLM = EOMONTH(__Date,-1)
  VAR __EOLMDay = DAY(__EOLM)
  VAR __Day = DAY(__Date)
  VAR __LMDay = IF(__EOLMDay < __Day, __Day, __EOLMDay)
  VAR __LMDate = DATE(YEAR(__EOLM),MONTH(__EOLM),__LMDay)
RETURN
  SUMX(FILTER(ALLSELECTED('Table',[Date]=__LMDate),[Sales])


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi  Greg_Deckler,

 

Thank you very much for your super quick solution, it worked fine

 

thanks again

 

dsmitha

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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