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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
AartiD
Helper II
Helper II

Average for Month Excluding Current Month Per Product Description

Suppose April is Current Month. Then Avg Sales per SKU will be Sum of Jan, Feb & March divided by 3. Now, if data is entered for May and May becomes Current Month , then Avg. Sales will be for Jan, Feb ,Mar, April divided by 4. , irrespective of sales for product is there in particular month. Average sales should change as and when month are selected or de-selected in Visual slicer.

I have Month as filter Slicer in Visuals of Power BI and I have to compare Current Month Sales to Avg.Previous Month Sales, hence to show Current Month data I have to select Current month say "April" in Filter Slicer, but Avg. figure should come as Average of Jan, Feb, Mar., it should not include April even if it is selected in Slicer.

 

Below is screen shot of excel file working and have also pasted same in case you want to incorporate data in excel. I have attached screen shot of Power Bi Visual as well. It is showing Avg. Sales till June (June beign current month) and average sales is caculated for month for which sales figures are available.It does not include months for which sales figure are not available for calculating average.

AartiD_2-1753256521759.png

 

Hospital NameProduct DescJanFebMarApril (Suppose Current Month)Avg. Sales Excluding Current Month =Sum(Jan, Feb, Mar)/3
Maruti HospitalBandage   100                                         -  
Maruti HospitalHandwasH-867840007000800                                    3,933
Maruti HospitalNova 18 Inj100  500                                        33
Maruti HospitalOperation Gowns   800                                         -  
Maruti HospitalTapes 2'20001000500                                    1,167
Susruta HospitalBandage                                             -  
Susruta HospitalCannula200                                           67
Susruta HospitalNova 18 Inj 90060070                                      500
Susruta HospitalOperation Gowns5001005050                                      217
Zen HospitalBandage600 10030                                      233
Zen HospitalDrapes                                             -  
Zen HospitalDrapes-12'   500                                         -  
Zen HospitalInjection   90                                         -  
Zen HospitalNova 18 Inj 2000                                        667

 

AartiD_4-1753256928883.png

 

2 ACCEPTED SOLUTIONS
wardy912
Super User
Super User

Hi @AartiD 

 If you want this to work for previous months in the current year only, you will need to identify the current month and current year in your average calculation. For this to work you will need a date table with month numbers related to your sales table. Assuming you have that, here's the solution:

First, a measure to show the current month sales

Current Month Sales = 
CALCULATE(
    SUM(Sales[SalesAmount]),
    Sales[Month] = SELECTEDVALUE('DateTable'[Month])
)

 

Then, the average calculation for previous months in the same year

Avg Sales Prev Months Same Year = 
VAR SelectedMonth = SELECTEDVALUE('DateTable'[MonthNumber])
VAR SelectedYear = SELECTEDVALUE('DateTable'[Year])
RETURN
    AVERAGEX(
        FILTER(
            ALL('DateTable'),
            'DateTable'[Year] = SelectedYear &&
            'DateTable'[MonthNumber] < SelectedMonth &&
            CALCULATE(SUM(Sales[SalesAmount])) > 0
        ),
        CALCULATE(SUM(Sales[SalesAmount]))
    )

 

I hope this helps, please give a thumbs up and mark as solved if it does, thanks!

View solution in original post

sreejad
Frequent Visitor

Hi @AartiD 

 

First create monthnumber column if its not already there and try below formula.

Measure = 
var MaxMonthNumber=MAX(Sheet1[Custom])
Var MonthCount=MaxMonthNumber-1
var Sales=CALCULATE(SUM(Sheet1[Value]),ALLEXCEPT(Sheet1,Sheet1[Hospital Name],Sheet1[Product Desc]),Sheet1[Custom]<MaxMonthNumber)
return
DIVIDE(Sales,MonthCount)

Custom is monthnumber, value is amount column.

sreejad_0-1753261828671.png

 

Thanks.

View solution in original post

6 REPLIES 6
v-nmadadi-msft
Community Support
Community Support

Hi @AartiD 

As we haven’t heard back from you, we wanted to kindly follow up to check if the suggestions  provided by the community members for the issue worked. Please feel free to contact us if you have any further questions.

 

Thanks and regards

v-nmadadi-msft
Community Support
Community Support

Hi @AartiD 

May I check if this issue has been resolved? If not, Please feel free to contact us if you have any further questions.


Thank you

Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1753506727809.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-nmadadi-msft
Community Support
Community Support

Hi @AartiD 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.


Thank you.

sreejad
Frequent Visitor

Hi @AartiD 

 

First create monthnumber column if its not already there and try below formula.

Measure = 
var MaxMonthNumber=MAX(Sheet1[Custom])
Var MonthCount=MaxMonthNumber-1
var Sales=CALCULATE(SUM(Sheet1[Value]),ALLEXCEPT(Sheet1,Sheet1[Hospital Name],Sheet1[Product Desc]),Sheet1[Custom]<MaxMonthNumber)
return
DIVIDE(Sales,MonthCount)

Custom is monthnumber, value is amount column.

sreejad_0-1753261828671.png

 

Thanks.

wardy912
Super User
Super User

Hi @AartiD 

 If you want this to work for previous months in the current year only, you will need to identify the current month and current year in your average calculation. For this to work you will need a date table with month numbers related to your sales table. Assuming you have that, here's the solution:

First, a measure to show the current month sales

Current Month Sales = 
CALCULATE(
    SUM(Sales[SalesAmount]),
    Sales[Month] = SELECTEDVALUE('DateTable'[Month])
)

 

Then, the average calculation for previous months in the same year

Avg Sales Prev Months Same Year = 
VAR SelectedMonth = SELECTEDVALUE('DateTable'[MonthNumber])
VAR SelectedYear = SELECTEDVALUE('DateTable'[Year])
RETURN
    AVERAGEX(
        FILTER(
            ALL('DateTable'),
            'DateTable'[Year] = SelectedYear &&
            'DateTable'[MonthNumber] < SelectedMonth &&
            CALCULATE(SUM(Sales[SalesAmount])) > 0
        ),
        CALCULATE(SUM(Sales[SalesAmount]))
    )

 

I hope this helps, please give a thumbs up and mark as solved if it does, thanks!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.