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
newgirl
Helper V
Helper V

Sort Matrix Table based on Count

Hi, guys!

 

I have a current PBI report that shows a matrix table listing down each complaint ticket and the details of these tickets, with a calendar slicer that lets the reader select any period they want to view the tickets for that period. The reader also sorts the matrix sometimes, could be according to date or according to Person Responsible, etc.

 

It works fine for now but then a manager requests that the table should have an option that can be sorted based on the count of complaints that a client has. 

 

My plan is to create a measure that would count how many tickets that a client has based on the matrix table shown and add this measure at the end of the matrix table so that the reader can just sort it based on that, if he wants.

However, I don't know how to create that certain measure that would only depend on the data shown in the matrix since I have a slicer involved. Based on what I've read, they usually add a calculated column but then again, the info on my matrix table depends on a calendar slicer.

 

Below are samples or if you have another idea, I would like to hear it.

 

Below is a sample raw data.

Complaint Ticket No.ClientDate RequestedPerson Responsible
1A1/1/2020Jane
2A1/5/2020Jane
3B2/1/2020John
4C12/1/2020Juniper
5D5/1/2020Jane
6A3/15/2020John
7B4/15/2020Juniper
8A6/30/2020John

 

Below is the sample matrix table that shows in my PBI report

 

Ex. Slicer is set from Jan 1, 2020 to April 30, 2020

Complaint Ticket No.ClientDate RequestedPerson Responsible
1A1/1/2020Jane
2A1/5/2020Jane
3B2/1/2020John
6A3/15/2020John
7B4/15/2020

Juniper

 

 

Below is my idea to add the measure in the matrix table. In this case, count of 3 for Client A rows since you can count 3 cases in the matrix. Count of 2 for Client B rows since there are 2 cases in the matrix.

 

Complaint Ticket No.ClientDate RequestedPerson ResponsibleCount
1A1/1/2020Jane3
2A1/5/2020Jane3
3B2/1/2020John2
6A3/15/2020John3
7B4/15/2020Juniper2

 

 

So that the reader can sort it according to number of complaints

 

Complaint Ticket No.ClientDate RequestedPerson ResponsibleCount
1A1/1/2020Jane3
2A1/5/2020Jane3
6A3/15/2020John3
3B2/1/2020John2
7B4/15/2020Juniper2
1 ACCEPTED SOLUTION

Hi @newgirl ,

 

You just need to add the Status to the ALLSELECTED part of the formula should be similar to this:

 

Responsible count =
CALCULATE (
    COUNT ( 'Table'[Complaint Ticket No.] );
    FILTER (
        ALLSELECTED (
            'Table'[Client];
            'Table'[Complaint Ticket No.];
            'Table'[Date Requested];
            'Table'[Person Responsible];
            'Table'[Status]
        );
        'Table'[Client] = SELECTEDVALUE ( 'Table'[Client] )
        &&    'Table'[Status] = SELECTEDVALUE ( 'Table'[Status] )
    )
)

Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

6 REPLIES 6
newgirl
Helper V
Helper V

Thank you so so so much @MFelix  for all the help! You're an angel!!!

MFelix
Super User
Super User

Hi @newgirl ,

 

Add the following measure to your model:

Responsible count =
CALCULATE (
    COUNT ( 'Table'[Complaint Ticket No.] );
    FILTER (
        ALLSELECTED (
            'Table'[Client];
            'Table'[Complaint Ticket No.];
            'Table'[Date Requested];
            'Table'[Person Responsible]
        );
        'Table'[Client] = SELECTEDVALUE ( 'Table'[Client] )
    )
)

 

Should work has expected:

MFelix_0-1606997430653.png

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix !

 

Thanks for replying!

 

I tried to do the measure on my own data but it said something like all tables inside the ALLSELECTED (?) must be the same. Then I realized that I wasn't able to include in my post that I have a Calendar table and the calendar table is what I use as my date slicer in the report, since I also need the Calendar to connect to other transactional data. 

 

How can I modify the measure to incorporate the Calendar table?

Hi @newgirl ,

 

I assume you have the relationship between both table made by the Date Requested and calendar like this:

 

Calendar Date 1 - > * Date Requested

 

If this is the relationship then no need to change anything in the measure I have given you. just replace the Table by the name of your correct table that has the requests information.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi, @MFelix  Thank you so much for your help! I've tried it and it's working perfectly!

I'm just so sorry to add one last question. Apparently, they wanted to include the status of the ticket whether it has been closed or open and they want to include that in the sorting too.

 

For example, this is the current table that's already working well.

1.JPG

They wanted to add the STATUS colum in the table and they wanted the order of the sorting to be all OPEN first and then the number of complaints per client. So if I add the Status, and sort it first before sorting the Responsible Count...

2.JPG

The Responsible Count for Client A for OPEN complaints should now be 2 instead of 3 while the count for its CLOSED complaints should now be 1 instead of 3. 

3.JPG

 

How can I incorporate the Status in the measure then?

Hi @newgirl ,

 

You just need to add the Status to the ALLSELECTED part of the formula should be similar to this:

 

Responsible count =
CALCULATE (
    COUNT ( 'Table'[Complaint Ticket No.] );
    FILTER (
        ALLSELECTED (
            'Table'[Client];
            'Table'[Complaint Ticket No.];
            'Table'[Date Requested];
            'Table'[Person Responsible];
            'Table'[Status]
        );
        'Table'[Client] = SELECTEDVALUE ( 'Table'[Client] )
        &&    'Table'[Status] = SELECTEDVALUE ( 'Table'[Status] )
    )
)

Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



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.