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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
yakovlol
Resolver I
Resolver I

Measure that used in matrix. Average by column hieraphy and Sum of Averages by rows hieraphy

Hello, community,

 

I have an unusual task to calculate measures in matrix table, that consists of 5 level hierarchy in rows and 3 level hierarchy in columns.

In columns, I have dates-weeks- month. And what I need is when dates are aggregated into week it shows the average
and when rows collapse those averages become sum of averages.

yakovlol_1-1727171336705.png

 

The question how to do calculation that will calculate the SUM of averaes by hierarchy

1 ACCEPTED SOLUTION
Selva-Salimi
Solution Specialist
Solution Specialist

Hi @yakovlol ,

 

in the case that @Shivu-2000 solution does not work you can try this....

 

to show in the value option of your natrix you need to write a measure as follows:

 

measure sum_average := var tbl = summarize(your_table, the name of column in the row of matrix , "Avg" , average  (what you have in you matrix right now) )

return

sumx(tbl,avg)

 

in this case if you are in the hierarchey level, the sum is the same as average and in top level they would be sum up.

 

If this post helps, then I would appreciate a thumbs up 👍 and mark it as the solution to help the other members find it more quickly. 

View solution in original post

4 REPLIES 4
Selva-Salimi
Solution Specialist
Solution Specialist

Hi @yakovlol ,

 

in the case that @Shivu-2000 solution does not work you can try this....

 

to show in the value option of your natrix you need to write a measure as follows:

 

measure sum_average := var tbl = summarize(your_table, the name of column in the row of matrix , "Avg" , average  (what you have in you matrix right now) )

return

sumx(tbl,avg)

 

in this case if you are in the hierarchey level, the sum is the same as average and in top level they would be sum up.

 

If this post helps, then I would appreciate a thumbs up 👍 and mark it as the solution to help the other members find it more quickly. 

Hello @Selva-Salimi Thanks for your approach. this is exactly what I need.

But i have another problem, maybe you know how to handle Average measure to calculate with blanks values.

But the real problem is that this blank rows in my table doesn't exist. they are only seen in my matrix table . I used this measure, but seems it doesn't work

AVERAGEX(KEEPFILTERS(ALL(table[Date])),[Sales]))

yakovlol_1-1727212430480.png

 

 


 

@yakovlol 

 

Maybe adding zero to sales calculation ([sales] +0) work for you. if not share more details.

 

If this post helps, then I would appreciate a thumbs up 👍

Shivu-2000
Resolver III
Resolver III

Hi @yakovlol 

So according to my understanding you have a matrix table that have 5-level row hierarchy and a 3-level column hierarchy (dates, weeks, and months), and you want to calculate averages when dates are aggregated to weeks and sums of averages when rows are collapsed (correct??).

 

To do so firstly you will have to Create Calculated Columns as

  • Week Number: Create a calculated column to extract the week number from the date column.
  • Month Number: Create a calculated column to extract the month number from the date column.

Than Create Measures:

  • Average Value: Create a measure to calculate the average of your desired value. For example:

    Average Value = AVERAGE([YourValue])
  • Sum of Averages: Create a measure to calculate the sum of averages. Use the CALCULATE function to modify the filter context:

    Sum of Averages = CALCULATE(
        [Average Value],
        ALLEXCEPT(YourTable, YourTable[Week Number])
    )

    This formula calculates the average value for each week and then sums them up, ignoring the filters applied at the row level.

 Configure Matrix Table:

  • Row Hierarchy: Add your 5-level hierarchy to the rows of the matrix table.
  • Column Hierarchy: Add your 3-level hierarchy (dates, weeks, months) to the columns.
  • Measures: Add the Average Value and Sum of Averages measures to the values area.

For Example:

If your table has columns Date, Region, Category, Product, Sales, and you want to calculate the average sales per week and the sum of averages per region, you might use the following measures:

Code snippet
Week Number = WEEKNUM([Date])
Month Number = MONTH([Date])

Average Sales = AVERAGE([Sales])
Sum of Average Sales = CALCULATE([Average Sales], ALLEXCEPT(YourTable, YourTable[Week Number]))

 

 

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

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.