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
ymobbs
Helper I
Helper I

Set up a slicer to filter numbers in different columns in Matrix

Hi,

 

I built up a Matrix in power bi. Like this one: 

 

CustomerArea 1Area 2Area 3
Customer 190000 210833
Customer 278000942299272
Customer 3109982345531000
Customer 44567 178078
Customer 5  117446
Customer 6 157835 
Customer 7 141947 
Customer 8  136120
Customer 9120431014 
Customer 10374 4490

 

I want to set up a slicer for 3 areas to be able to sort data in different columns. For example, I choose Area 1, then the whole table will be sorted by descending order of numbers in Area 1 column. 

 

Is that doable in power bi? 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Hello @ymobbs 

You can do what you are looking for, you will just need an extra table and some additional measures.  I assume your matrix is set up with customer on the rows and area on the columns with an amount in the values.  We will have to change that a bit to fit the sort measure in but it's not too bad.

 

First we need a table of the areas.

Area Table = 
DATATABLE(
    "Area",STRING,
    {
        {"Area 1"},
        {"Area 2"},
        {"Area 3"}
    }
)

Then we have a measure to sum the amount and a measure for each of the areas.

Total Amount = SUM ( YourTable[Amount] )
Area 1 Amount = CALCULATE ( [Total Amount], KEEPFILTERS ( YourTable[Area] = "Area 1" ) )
Area 2 Amount = CALCULATE ( [Total Amount], KEEPFILTERS ( YourTable[Area] = "Area 2" ) )
Area 3 Amount = CALCULATE ( [Total Amount], KEEPFILTERS ( YourTable[Area] = "Area 3" ) )

Then the sorting measure that will read the slicer we put over the top of the Area table.

Sort Measure = 
VAR SelectedArea = SELECTEDVALUE ( 'Area Table'[Area], "Area 1" )
RETURN
SWITCH (
    TRUE (),
    SelectedArea = "Area 1", [Area 1 Amount],
    SelectedArea = "Area 2", [Area 2 Amount],
    SelectedArea = "Area 3", [Area 3 Amount]
)

You make the slicer on area and add the 4 measures into your matrix then set the sort on the matrix to be by [Sort Measure]

customersort.jpg

Once you get it working the way you want you can set the [Sort measure] column to be so narrow you can't see it. 

I would set the slicer to be single select only but in my sorting measure I did set the default to use Area 1.  If the user selects 2 areas to sort by the measure will not know which to use so it will default back to Area 1.  Just something to be aware of.

I have attached my sample .pbix file for you to take a look at.

 

 

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

Yes, but you will likely need to create a measure that does a RANKX or returns the value from Area1, Area2 and Area3 based upon the measure selection. You would add that to your matrix visualization and hide the column by turning off word wrap and shrinking it. Then, you could sort the matrix visual by that measure. 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
jdbuchanan71
Super User
Super User

Hello @ymobbs 

You can do what you are looking for, you will just need an extra table and some additional measures.  I assume your matrix is set up with customer on the rows and area on the columns with an amount in the values.  We will have to change that a bit to fit the sort measure in but it's not too bad.

 

First we need a table of the areas.

Area Table = 
DATATABLE(
    "Area",STRING,
    {
        {"Area 1"},
        {"Area 2"},
        {"Area 3"}
    }
)

Then we have a measure to sum the amount and a measure for each of the areas.

Total Amount = SUM ( YourTable[Amount] )
Area 1 Amount = CALCULATE ( [Total Amount], KEEPFILTERS ( YourTable[Area] = "Area 1" ) )
Area 2 Amount = CALCULATE ( [Total Amount], KEEPFILTERS ( YourTable[Area] = "Area 2" ) )
Area 3 Amount = CALCULATE ( [Total Amount], KEEPFILTERS ( YourTable[Area] = "Area 3" ) )

Then the sorting measure that will read the slicer we put over the top of the Area table.

Sort Measure = 
VAR SelectedArea = SELECTEDVALUE ( 'Area Table'[Area], "Area 1" )
RETURN
SWITCH (
    TRUE (),
    SelectedArea = "Area 1", [Area 1 Amount],
    SelectedArea = "Area 2", [Area 2 Amount],
    SelectedArea = "Area 3", [Area 3 Amount]
)

You make the slicer on area and add the 4 measures into your matrix then set the sort on the matrix to be by [Sort Measure]

customersort.jpg

Once you get it working the way you want you can set the [Sort measure] column to be so narrow you can't see it. 

I would set the slicer to be single select only but in my sorting measure I did set the default to use Area 1.  If the user selects 2 areas to sort by the measure will not know which to use so it will default back to Area 1.  Just something to be aware of.

I have attached my sample .pbix file for you to take a look at.

 

 

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.