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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Arashi
Frequent Visitor

How to sum and average at same column with different aggregation levels

Hello,

I hope you can help me with this. I'm sure it is quite simple but I don't seem to find the right measure.

 

I need the create a column in my matrix that creates the sum up of the number of products by store level on year 2022. However when the matrix is grouped by type of store level, it should show the average of the number of products.

 

I'm using something like:

IF (ISFILTERED (Table [Type of Store] , CALCULATE (AVERAGE (Table [#Products], Table [Year] = "2022") ,

CALCULATE (SUM (Table [#Products], Table [Year] = "2022"))

 

But this is not working at all, the result is not even a correct average of the number of products.

 

Expected result shoul be:

Arashi_0-1649241464101.png

 

Find below the dataset you can use to replicate the situation:

 

StoreType of StoreCategory#ProductsYear
11BCategory102021
11BCategory118602022
11BCategory202021
11BCategory202022
11BCategory302021
11BCategory38382022
11BCategory402021
11BCategory402022
25BCategory26582021
25BCategory213192022
25BCategory34842021
25BCategory372022
25BCategory44302021
25BCategory45032022
25BCategory59152021
25BCategory502022
65DCategory23152021
65DCategory23462022
65DCategory47782021
65DCategory42202022
65DCategory5282021
65DCategory502022
112DCategory11812021
112DCategory13662022
112DCategory29422021
112DCategory202022
112DCategory36142021
112DCategory32252022
112DCategory41712021
112DCategory402022
2052CCategory202021
2052CCategory24892022
2052CCategory302021
2052CCategory31962022
2052CCategory402021
2052CCategory43132022
2052CCategory502021
2052CCategory52172022
2067CCategory2442021
2067CCategory25452022
2067CCategory32782021
2067CCategory31362022
2067CCategory47722021
2067CCategory43862022
2067CCategory51862021
2067CCategory51742022
3254ECategory29102021
3254ECategory202022
3254ECategory34982021
3254ECategory302022
3254ECategory42822021
3254ECategory402022
3254ECategory51202021
3254ECategory502022
4534ECategory2412021
4534ECategory202022
4534ECategory38752021
4534ECategory302022
4534ECategory45872021
4534ECategory402022
4534ECategory55412021
4534ECategory502022
6756ACategory17302021
6756ACategory117172022
6756ACategory22472021
6756ACategory23132022
6756ACategory36992021
6756ACategory39112022
6756ACategory41342021
6756ACategory46392022
7866CCategory27372021
7866CCategory26992022
7866CCategory39512021
7866CCategory31322022
7866CCategory4822021
7866CCategory43382022
7866CCategory55802021
7866CCategory52262022

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @Arashi,

You can take a look at the following blog about how to use Dax expression to check the current row context levels.

You can use if statements with these filters to check hierarchy level and write corresponding expressions to replace that level calculation:

Clever Hierarchy Handling in DAX - SQLBI

Regards,

Xiaoxin Sheng

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

HI @Arashi,

You can take a look at the following blog about how to use Dax expression to check the current row context levels.

You can use if statements with these filters to check hierarchy level and write corresponding expressions to replace that level calculation:

Clever Hierarchy Handling in DAX - SQLBI

Regards,

Xiaoxin Sheng

daXtreme
Solution Sage
Solution Sage

To do such calculations you have to use ISINSCOPE to figure out which level you're working with and then perform the correct aggregation. Have a look at this vid ISINSCOPE - DAX Guide - YouTube.

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.