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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
nidhijo
Frequent Visitor

Calculating avg based on number of months

Hi all!!

 

I have data that contains quantity ordered and has the dates assosicated with the orders, what I want to calculate is an average of the quantity ordered calculated by number of months. For eg: for the time period june 2019-june 2020 the calculation would be =total number of orders/13 (number of months)  

 

I am doing this to be able to plot an avg line in a line and column chart that shows the quanity ordered by months: 

 

nidhijo_0-1636868463463.png

 

The avg should be indicated by the dark blue line but clearly it is wrong. Also, how can I remove the previous months that have no orders for this particular location, every location has different data...

 

I also thought of calculating the number of months from the first month ordered till current month, but I'm struggling to do that as well..  

 

Sorry if this is too complicated but any help would be greatly appreciated!!! I'm relatively new to power BI and I've been struggling with this report for the past few days. 

 

Thank you 🙂

 

4 REPLIES 4
v-chenwuz-msft
Community Support
Community Support

Hi @nidhijo ,

 

Depend on you chart, I create some data. 

AVARAGE Quantity =
VAR _total =
    SUMX( ALL( 'Table' ), [Orders] ) 
// If you have condition to calculate the number of quantity order, you can use SUMX(FILTER(ALL('Table'),conditions),[Orders])
VAR _numOfmonth =
    COUNTROWS(
        FILTER(
            SUMMARIZE( ALL( 'Table' ), 'Table'[Date], "sum", SUM( 'Table'[Orders] ) ),
            [sum] > 0
        )
    )
RETURN
    _total / _numOfmonth
//  If you do not want to display the blank months , try following
// IF(ISBLANK([Quantity orders]),BLANK(),_total/_numOfmonth)

The result:

vchenwuzmsft_0-1637138921059.png

OR

vchenwuzmsft_1-1637139064720.png

I put my pbix file in the attachment and you can refer, if I misunderstood you, please let me know.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

nidhijo
Frequent Visitor

I can't use the analytics pane as it is only for the line visual, if I convert this to line visual it does not show me the distrubution for each month which I would like to see. Thanks for the link I'll check out your blog. Also, do you know how I could remove the previous months with no data from my visual? @Greg_Deckler 

@nidhijo To remove the previous months with no data, you need your measures that are returning data in those months to return BLANK instead.



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@nidhijo Can't you just use the Analytics pane's Average feature? Otherwise it is a measure aggregation problem. This looks like a measure aggregation problem. See my blog article about that here: https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149

The pattern is:
MinScoreMeasure = MINX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
MaxScoreMeasure = MAXX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
AvgScoreMeasure = AVERAGEX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
etc.



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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