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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
azaterol
Helper V
Helper V

Previous year and month

Hello everyone,

I have a matrix with dates and a quantity column.
The second quantity column should show quantities from the previous year. That is, if there are 208 quantities in September 2022 and there are 221 quantities in September 2021, it should be displayed in the column "Quantity previous year".

 

Do you have an idea for a measure?

 

Initual sitation:

azaterol_2-1663675187141.png

 

 

 

 

azaterol_1-1663675105924.png  

Expected situation:

azaterol_3-1663675492334.png

 

 

 

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @azaterol ;

You could create a measure as follow:

 

Measure = CALCULATE(SUM('Order'[Quantity]),FILTER(ALL('Date'),EOMONTH([Date],0)=EOMONTH(MAX('Date'[Date]),-12)))

 

The final show:

vyalanwumsft_0-1663741043237.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-yalanwu-msft
Community Support
Community Support

Hi, @azaterol ;

You could create a measure as follow:

 

Measure = CALCULATE(SUM('Order'[Quantity]),FILTER(ALL('Date'),EOMONTH([Date],0)=EOMONTH(MAX('Date'[Date]),-12)))

 

The final show:

vyalanwumsft_0-1663741043237.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yalanwu-msft  works perfect! Thank you! Smart and easy to understand!!

lazurens2
Frequent Visitor

 

Maybe this version could help : 

Sales PY = 
VAR __Current = MAX('Sales Calendar'[Sales Date])
  VAR __PrevStart = DATE(YEAR(__Current)-1,MONTH(__Current),DAY(__Current))
  VAR __PrevEnd = DATE(YEAR(__Current)-1,MONTH(__Current),DAY(__Current))
RETURN
  SUMX(FILTER('Metrics','Metrics'[Sales_Date] >= __PrevStart && 'Metrics'[Sales_Date] <= __PrevEnd),'Metrics'[Sales€])

 

Greg_Deckler
Super User
Super User

@azaterol Try:

Quantity previous year measure =
  VAR __Start = MIN('Table'[Date])
  VAR __End = MAX('Table'[Date])
  VAR __PrevStart = DATE(YEAR(__Start)-1,MONTH(__Start),DAY(__Start))
  VAR __PrevEnd = DATE(YEAR(__End)-1,MONTH(__End),DAY(__End))
RETURN
  SUMX(FILTER('Table',[Date] >= __PrevStart && [Date] <= __PrevEnd),[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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

 

Hello, unfortunately it didn't work. Here is the sample file. At the end what do you mean by value?

 

https://easyupload.io/vbtdp9

 

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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