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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
ymobbs
Helper I
Helper I

How to Use a Historical Monthly Average for the Furture Months?

Hi, 

 

I have a project that I need to calculate the average selling price (ASP) from certain months then use it as the ASP for future months.  

 

I have a simplified table of my project:

CustomerMonthVolumeRevenue
AJAN20100
BJAN25150
AFEB15125
BFEB30500
CFEB23400
AMAR21350
BMAR50750
CMAR24160
DMAR851200
EMAR65950
EAPR35 
BAPR26 
BMAY45 
CMAY24 
CMAY59 

 

In this example, I need to calculate the ASP from Jan, Feb and Mar then use it as the ASP for Apr and May in a Table or Matrix in Power BI. I tried Calculate but the filter part of the meausre made it only calculate when the months are JAN or Feb or Mar. I'm totally lost here. Any help would be appreciated!!

 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @ymobbs 

 

You can try this measure

ASP = 
var _lastMonth = CALCULATE(MAX('Table'[Month Number]),ALL('Table'),'Table'[Revenue]<>BLANK())
var _totalRevenue = CALCULATE(SUM('Table'[Revenue]),ALL(Months[Month]),'Months'[MonthNumber]<=_lastMonth)
var _totalVolume = CALCULATE(SUM('Table'[Volume]),ALL(Months[Month]),'Months'[MonthNumber]<=_lastMonth)
return
IF(MAX(Months[MonthNumber])>_lastMonth,DIVIDE(_totalRevenue,_totalVolume))

 

I create two Dim tables Customers and Months with below code and use them in the matrix visual. This would avoid missing data when there is no data in some months in the data table. And create relationships between Dim tables and Data table. 

Customers = VALUES('Table'[Customer])
Months = DISTINCT(SELECTCOLUMNS('Table',"MonthNumber",'Table'[Month Number],"Month",'Table'[Month]))

 

Result

vjingzhang_0-1648790470569.png

Download the attachment to see details. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

6 REPLIES 6
v-jingzhang
Community Support
Community Support

Hi @ymobbs 

 

You can try this measure

ASP = 
var _lastMonth = CALCULATE(MAX('Table'[Month Number]),ALL('Table'),'Table'[Revenue]<>BLANK())
var _totalRevenue = CALCULATE(SUM('Table'[Revenue]),ALL(Months[Month]),'Months'[MonthNumber]<=_lastMonth)
var _totalVolume = CALCULATE(SUM('Table'[Volume]),ALL(Months[Month]),'Months'[MonthNumber]<=_lastMonth)
return
IF(MAX(Months[MonthNumber])>_lastMonth,DIVIDE(_totalRevenue,_totalVolume))

 

I create two Dim tables Customers and Months with below code and use them in the matrix visual. This would avoid missing data when there is no data in some months in the data table. And create relationships between Dim tables and Data table. 

Customers = VALUES('Table'[Customer])
Months = DISTINCT(SELECTCOLUMNS('Table',"MonthNumber",'Table'[Month Number],"Month",'Table'[Month]))

 

Result

vjingzhang_0-1648790470569.png

Download the attachment to see details. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

@v-jingzhang Thank you so much! I was able to plug the measure in to make it worked. 

 

However, it might a issue once the time goes forward when it includes 2 years of data. When it comes, the measure has to change from basing on "Month" to "Date". No rush, but would you please adjust the measure to make it work when mutiple of years of data included. Thank you again!

Hi @ymobbs 

 

When you have Date column and data of multiple years, I recommend to add a Date table to the model. Build a relationship between Date table and the fact table on their Date columns (one-to-many, single filter direction). In the Date table, add a YearMonth column to have values like 202201, 202202, 202203... for months in all years. Then use this YearMonth column to replace the original MonthNumber column in my previous measure. Remove the Months table in my previous reply and use the Date table instead. 

 

Using a Date table is a common and recommended practice when you want to make date-related calculations.  

Do You Need a Date Dimension? - RADACAD

Power BI Date or Calendar Table Best Method: DAX or Power Query? - RADACAD

 

Best regards,

Jing

@v-jingzhang Thank you again for such a through explanation and your patience! 

ymobbs
Helper I
Helper I

 AprAprMayMay
 VolumeASPVolumeASP
C    
B    
E    

@amitchandak Thank  you so much for your response! 

 

However, I don't quite understand the formulas you wrote. What is the ASP in the first three measures? I don't have it in my original data tabel.  Which one of the measures that I can put in the Values in a Matrix (Above) to show the ASP for Apr and May?

 

 

amitchandak
Super User
Super User

@ymobbs , You can get formula likes

 


MTD ASP= CALCULATE([ASP] ,DATESMTD('Date'[Date]))
last MTD ASP= CALCULATE([ASP],DATESMTD(dateadd('Date'[Date],-1,MONTH)))

2nd last MTD ASP= CALCULATE([ASP],DATESMTD(dateadd('Date'[Date],-2,MONTH)))

 

using today

 

This month Today =
var _min = eomonth(today(),-1)+1
var _max = eomonth(today(),0) //today()
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Date] >= _min && 'Date'[Date] <=_max ) )

 

last month Today =
var _min = eomonth(today(),-2)+1
var _max = eomonth(today(),-1) //today()
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Date] >= _min && 'Date'[Date] <=_max ) )

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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