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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

DAX code request to calculate the average sales across all the stores.

 Hi

 

The below chart show the sales qty of a store A12 and I would like to draw a Horizontal line on the chart to display the average sales of each week across number of stores for StoreGroup Alpha.

 

pbi.JPG

 

I have attached the sample data as well for your reference. P

lease can someone help me with the DAX code to achieve the result.

 

https://drive.google.com/file/d/1GAZhMuXREG0ZxzcSDbMrPUdtT79VGqDG/view?usp=sharing 

 

Thanks
Mahad

1 ACCEPTED SOLUTION

Hi,

Thank you for your feedback.

Please check the attached file, that I fixed the measure.

QTY group avg fix: =
VAR _currentgroup =
    MAX ( Store_Master[StoreGroup] )
VAR _storelist =
    CALCULATETABLE (
        VALUES ( Store_Master[Store ID] ),
        FILTER ( ALL ( Store_Master ), Store_Master[StoreGroup] = _currentgroup )
    )
VAR _storeslistinagroup =
    ADDCOLUMNS (
        _storelist,
        "@qty", CALCULATE ( SUM ( 'Sales Table'[All Qty (ex Mat9)] ) )
    )
VAR _storecount =
    COUNTROWS ( _storelist )
RETURN
    SUMX ( _storeslistinagroup, [@qty] ) / _storecount

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

6 REPLIES 6
johnt75
Super User
Super User

You can get the average sales for the store group with

Avg group sales = CALCULATE( AVERAGE('Sales Table'[Qty]), ALLSELECTED('Date'), ALLSELECTED(Store_Master[StoreGroup] ) )

but you will need to place some filters on the visual to only show the weeks you are interested in, otherwise it will return a value for all the weeks in the date table

Jihwan_Kim
Super User
Super User

Hi,

Please check the attahced pbix file down below.

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Anonymous
Not applicable

Hi Jihwan

 

Thanks for your quick help.

I have brought all the stores for a particular week to see the average. The code is working fine and displaying the correct average,

345/8 = 43.1

 

Can you also please suggest to calculate the average out of all the stores in StoreGroup Alpha.

345/12 = 28.75

 

PBI report.JPG

Appreciate your help.

 

Thanks

Mahad

Hi,

Thank you for your feedback.

Please check the attached file, that I fixed the measure.

QTY group avg fix: =
VAR _currentgroup =
    MAX ( Store_Master[StoreGroup] )
VAR _storelist =
    CALCULATETABLE (
        VALUES ( Store_Master[Store ID] ),
        FILTER ( ALL ( Store_Master ), Store_Master[StoreGroup] = _currentgroup )
    )
VAR _storeslistinagroup =
    ADDCOLUMNS (
        _storelist,
        "@qty", CALCULATE ( SUM ( 'Sales Table'[All Qty (ex Mat9)] ) )
    )
VAR _storecount =
    COUNTROWS ( _storelist )
RETURN
    SUMX ( _storeslistinagroup, [@qty] ) / _storecount

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Anonymous
Not applicable

Dear Jihwan

 

Thank you for your help to achieve the result. You are a star.

Please can you advise/suggest me how can I learn and master in DAX from the scratch.

I'm looking to learn from 1-2-1 instead of some online recorded videos which would not give me the privilege of clarifying my doubts.

Thanks

Mahad

 

amitchandak
Super User
Super User

@Anonymous ,

 

Averagex(Value(Date[Week]), [Sales Measure])

 

or

calculate(Averagex(Value(Date[Week]), [Sales Measure]), allselected())

 

or

 

calculate(Averagex(Summarize(Sale, Sales[Store],Date[Week],"_1", [Sales Measure]), [_1]),allselected())

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.