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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
kashanka
New Member

Challenge with SUM of AVERAGES

Hello PBI Community!

 

So, I have a challenge with DAX. My end-users want to see AVERAGE of products sold for each weekday but the Grand Total should be a SUM of these AVERAGES. I wrote some DAX:

 

So my code looks like that:

    sumOfAverages = 
VAR avgFull =
CALCULATE (
SUM ( [sold_qt] )
/ DISTINCTCOUNT ( [delivery_date] )
)
RETURN
IF (
HASONEVALUE ( [weekday_name] ),
avgFull,
SUMX ( VALUES ( date_weekday_dim[weekday_name] ), avgFull )
)

Actually it's working only if I have selected all the weekdays. See the screen below.pbi_dax.PNG  If I select something on slicers and there won't be any data from particular weekday it looks like that.

Capture.PNG

So the Grand Total is not correct. I think that there's a problem with SUMX (VALUES ... )) section in DAX but really don't know how to figure it out. 

Could you help me with this, please?:)

3 REPLIES 3
amitchandak
Super User
Super User

@kashanka , also use isinscope

https://www.kasperonbi.com/use-isinscope-to-get-the-right-hierarchy-level-in-dax/

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
Nathaniel_C
Community Champion
Community Champion

Hi @kashanka ,
Created a table, then on visuals a slicer, and a matrix, then a measure.

table.PNG

 

table 2.PNG

 

 

Sum of Daily Averages = SUMX(DailyAverages,Divide(DailyAverages[Sold],DailyAverages[DistinctCount]))

This should work if I understand your issue.


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @kashanka ,

If one of the days has no values...table 3.PNG

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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