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

Get Previous Month, Previous Year and Previous 2 Years Data

Hi, 

 

I would like to ask for your help. How can I get the "Previous month Average Temperature (Whole month)" 

I have my date dimension and fact table for the temperature but I am not getting my desired result. Below is my dax. 

 

Previous Month: 
CALCULATE(AVERAGE(FACT_WEATHER[MAX_TEMP]) + AVERAGE(FACT_WEATHER[MIN_TEMP])/2,
DATEADD('DIM_CALENDAR'[Date], -1, MONTH)
)
 
Can I do the same for previous year and previous 2 years?
 

Here's my sample data and expected answer:

 

YearMonthDay Average Temperature 
2023July1                                 30.90
2023July2                                 29.10
2023July3                                 29.80
2023July4                                 29.50
2023July5                                 30.15
2023July6                                 30.80
2023July7                                 29.90
2023July8                                 29.90
2023July9                                 29.95
2023July10                                 28.65
2023July11                                 29.45
2023July12                                 29.70
2023July13                                 24.80
2023July14                                 27.50
2023July15                                 27.25
2023July16                                 27.25
2023July17                                 28.20
2023July18                                 28.95
2023July19                                 28.30
2023July20                                 28.70
2023July21                                 29.55
2023July22                                 28.60
2023July23                                 28.60
2023July24                                 28.35
2023July25                                 28.80
2023July26                                 28.15
2023July27                                 27.35
2023July28                                 27.20
2023July29                                 26.55
2023July30                                 26.35
2023July31                                 27.00
2023Aug1                                 25.70
2023Aug2                                 26.85
2023Aug3                                 27.90
2023Aug4                                 28.45

 

Expected Values: 
  
Current Month Average Temp (August 1 -5)Previous Month Average Temp (July 1-31)
                                            27.22                                              28.56
 
Thanks!
1 ACCEPTED SOLUTION

Hi @icdns ,

Please check the pbix file.

vcgaomsft_0-1692778454264.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

7 REPLIES 7
icdns
Post Patron
Post Patron

Here's my sample data and expected answer:

 

YearMonthDay Average Temperature 
2023July1                                 30.90
2023July2                                 29.10
2023July3                                 29.80
2023July4                                 29.50
2023July5                                 30.15
2023July6                                 30.80
2023July7                                 29.90
2023July8                                 29.90
2023July9                                 29.95
2023July10                                 28.65
2023July11                                 29.45
2023July12                                 29.70
2023July13                                 24.80
2023July14                                 27.50
2023July15                                 27.25
2023July16                                 27.25
2023July17                                 28.20
2023July18                                 28.95
2023July19                                 28.30
2023July20                                 28.70
2023July21                                 29.55
2023July22                                 28.60
2023July23                                 28.60
2023July24                                 28.35
2023July25                                 28.80
2023July26                                 28.15
2023July27                                 27.35
2023July28                                 27.20
2023July29                                 26.55
2023July30                                 26.35
2023July31                                 27.00
2023Aug1                                 25.70
2023Aug2                                 26.85
2023Aug3                                 27.90
2023Aug4                                 28.45

 

Expected Values: 
  
Current Month Average Temp (August 1 -5)Previous Month Average Temp (July 1-31)
                                            27.22                                              28.56

Please try the Parallel period Dax , explained in the below tutorial. You can create the AVG dax instead of SUM.

 

DAX Functions: ParallelPeriod() vs. SamePeriodLastYear() - Explained with Examples | MiTutorials - Y...

Hi,

Please find attached the PBI file.

Hope this helps.

Ashish_Mathur_0-1692153970486.png

 


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

Hello, 

 

Thank you for this but i won't be displaying the temp together with the month. I will only display it separately that's why I need it as a dax 😞 

Hi @icdns ,

Please check the pbix file.

vcgaomsft_0-1692778454264.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Hi,

I really do not know the result that you want.


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

Hi @icdns 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

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.