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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
BdC2
New Member

Problem with Average

I am quite new to PowerBI and really struggling with something I feel should be quite simple... Average...

I have a set of data that has location, product name, Qty and Data Week. The normal Average function causes that ALL quatities are added and devided by the number of products, but I need an average of total quantity per location, per data week, regardless of the number of products in the list.

 

I need th average to be based on the total quantity for each week. because I have various products in each data week, it is dividing by the number of lines and not the number of weeks, so essentially the total quantity needs to be divided in the below case by 2 (Data Week 1 and 2 = 2) and not the total number of lines. If that makes sense?

 

LocationProduct NameQty on HandData Week
AProduct 12001
AProduct 23001
AProduct 32001
AProduct 41001
AProduct 11002
AProduct 23002
AProduct 33002
AProduct 41002
BProduct 1501
BProduct 22001
BProduct 33001
BProduct 45001
BProduct 12002
BProduct 26002
BProduct 32002
BProduct 43002
1 ACCEPTED SOLUTION

The solution that ended up working for my set of data was:

 

TotalQtyPerWeek = 

CALCULATE(

SUM('Table'[Qty on Hand]),

ALLEXCEPT('Table','Table'[Location],'Table'[Date Week],'Table'[Product Name])

)

 

WeeksCount = 

CALCULATE(

DISTINCTCOUNT('Table'[Data Week]),

ALLEXCEPT('Tabke','Table'[Location],'Table'[Product Name])

)

 

AverageQtyPerWeek =
DIVIDE(
[TotalQtyPerWeek],
[WeeksCount]
)

View solution in original post

4 REPLIES 4
BdC2
New Member

I was still getting a very weird average, but I ended up adding some extra ALLEXCEPT conditions and it seems to have worked.

DAX
TotalQtyPerWeek =
CALCULATE(
SUM('Table'[Qty on Hand]),
ALLEXCEPT('Table', 'Table'[Location], 'Table'[Data Week],'Table'[Product Name])
)

 

Create a measure for the number of weeks per location:

DAX
WeeksCount =
CALCULATE(
DISTINCTCOUNT('Table'[Data Week]),
ALLEXCEPT('Table', 'Table'[Location],'Table'[Product Name])
)

 

thank you

Hi @BdC2 ,

We really appreciate your efforts and for letting us know the update on the issue.

Please continue using fabric community forum for your further assistance.

If this is the solution that has worked for you please accept your reply as solution so as to help other community members who may face similar issue in the future

Thank you for reaching out to us on the Microsoft Fabric Community Forum.

 

The solution that ended up working for my set of data was:

 

TotalQtyPerWeek = 

CALCULATE(

SUM('Table'[Qty on Hand]),

ALLEXCEPT('Table','Table'[Location],'Table'[Date Week],'Table'[Product Name])

)

 

WeeksCount = 

CALCULATE(

DISTINCTCOUNT('Table'[Data Week]),

ALLEXCEPT('Tabke','Table'[Location],'Table'[Product Name])

)

 

AverageQtyPerWeek =
DIVIDE(
[TotalQtyPerWeek],
[WeeksCount]
)

bhanu_gautam
Super User
Super User

@BdC2 Create a measure for total quantity per location per week:

DAX
TotalQtyPerWeek =
CALCULATE(
SUM('Table'[Qty on Hand]),
ALLEXCEPT('Table', 'Table'[Location], 'Table'[Data Week])
)

 

Create a measure for the number of weeks per location:

DAX
WeeksCount =
CALCULATE(
DISTINCTCOUNT('Table'[Data Week]),
ALLEXCEPT('Table', 'Table'[Location])
)

 

Create the final measure for the average quantity per location per week:

DAX
AverageQtyPerWeek =
DIVIDE(
[TotalQtyPerWeek],
[WeeksCount]
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.