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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
IK181
New Member

Power BI Report Builder - Total of Top N by Group Filtering in Matrix

Hi All, 

 

Hope all is well.

I am working on a paginated report which contains a matrix made of

 two Row groups having

  1. Main Category as a Parent Group and
  2. Area as Child Group

and have a 1 column group of Report Date with a column named "current date" & "previous date".

The resultant needs to be top 10 Area which was easy to achieve but the issue is unable to calculate the Grand total of top 10 returning Areas.

 

Would really appreciate if anyone can assist me in this regard and let me know how to calculate the Grand Total of Top 10 Areas in a matrix.

3 REPLIES 3
IK_181
New Member

Please assist me if possible, I'll be grateful to you.

IK_181
New Member

Thank you for the assistance, Sahir. 
However, the given solution isn't returning the filtered rows total.

I have tried your solution for Top 2 rows, keeping everthing quite simple.

IK_181_2-1691017042473.png


This is the design view: I have chosen Branch Banking in the Main Category group only.

IK_181_3-1691017474793.png

This is the resultant view: Sum should be 7 instead of 9.

IK_181_1-1691016863286.png

 

Sahir_Maharaj
Super User
Super User

Hello @IK181,

 

Can you please try the following:

 

1. Define a custom code function in the report:

Dim TotalTop10Areas As Integer = 0

Public Function AddToTotalTop10Areas(ByVal value As Integer) As Integer
    TotalTop10Areas = TotalTop10Areas + value
    Return value
End Function

Public Function GetGrandTotalTop10Areas() As Integer
    Return TotalTop10Areas
End Function

2. Add a textbox to your report where you want to display the grand total. In the Value property of the textbox:

=Code.GetGrandTotalTop10Areas()

3. In the cell of the matrix where you want to calculate the top 10 areas, add a custom expression to handle the top 10 calculation

=Code.AddToTotalTop10Areas(Sum(Fields!ValueToSum.Value))

4. Sort the matrix rows by the sum of the values in descending order.

 

Should you need further assistance please don't hesitate to reach out to me.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution?
➤ Lets connect on LinkedIn: Join my network of 13K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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