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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Madhu7624
Regular Visitor

Sorting Data in Different Order Based on Slicer Selection in Power bi

Hi Everyone,

I want to sort the data in a specific order. When I select a value in the slicer.

Below is the raw data:

Table : 

YearMonthProductAmount
20231AA100
20232BB200
20233CC100
20234DD100
20235EE300
20241AA300
20242CC500
20244DD600
20245ZZ300
20246BB300



slicer : 

Madhu7624_1-1737134706326.png



order Required 

The order in which the products need to be sorted, when we select the year from slicer.

Madhu7624_0-1737134548981.png



1 ACCEPTED SOLUTION

Try this ....

 

Create a "driver table" ...

speedramps_0-1737302509851.png

 

 Click on Sortkey and unpivot other columns

Rename atttubute to Year

Rename Value to Product

Change the datya types

speedramps_2-1737302611975.png

 

Add a M:M Prodcut relationship to your data

speedramps_3-1737302699163.png

 

 

 

Create 2 measures

Sorted product = 
SELECTEDVALUE(driver[Product])

 

Sales = 
CALCULATE(
SUM(yourdata[Amount]),
yourdata[Year] = SELECTEDVALUE(driver[Year]))

 

Add Matrix visual 

speedramps_4-1737303010358.png

 

Change the row text colour to white

and change the Rows filedname to a single space

to hide it

speedramps_5-1737303118526.pngspeedramps_6-1737303173730.png

user the Driver year and not yourdate year in the slicer ... otherwise the solutoion will not work

speedramps_7-1737303376121.png

 

 

Please click [accept solution] and the thumbs up button. Thank you

View solution in original post

5 REPLIES 5
rohit1991
Super User
Super User

To sort data based on slicer selection in Excel:

  1. Create Sorting Table:  Map products to the required order for each year.

  2. Add Helper Column: Example formula: =IF(A2=2023, VLOOKUP(B2, SortingTable!$A$1:$C$6, 2, FALSE),
    VLOOKUP(B2, SortingTable!$A$1:$C$6, 3, FALSE))

    Use VLOOKUP or INDEX-MATCH to fetch the sort order dynamically based on the slicer-selected year.
  3. Link Slicer: Connect the slicer to filter data by year.

  4. Sort Data: Sort using the helper column.

Power BI

speedramps
Super User
Super User

You description is a bit confussing.

 

Please provide example input data as table (not a screen print)

and the desire output

with a clear decsription

and omit any irreleant data and infomation.

 

you seem to be saying you want the data in C, E, B, D, A sequence instead of  A, B, C, D, E

 

That is easy ...

just create a seperate table with 2 columns

 

Product Sortkey
C 1
E 2
B 3

 

Then sort product by sortkey

learn how here

https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-sort-by-column 

 

Please click [accept solution] and [thumbs up]

The issue is that, for example, Product "AA" is present in both 2023 and 2024. I want Product "AA" to be displayed in one order for 2023 and a different order for 2024.

I have attached an image showing the required sort order for 2023 and 2024. As you can see, the sort order for product 's in 2023 is different from 2024.

Try this ....

 

Create a "driver table" ...

speedramps_0-1737302509851.png

 

 Click on Sortkey and unpivot other columns

Rename atttubute to Year

Rename Value to Product

Change the datya types

speedramps_2-1737302611975.png

 

Add a M:M Prodcut relationship to your data

speedramps_3-1737302699163.png

 

 

 

Create 2 measures

Sorted product = 
SELECTEDVALUE(driver[Product])

 

Sales = 
CALCULATE(
SUM(yourdata[Amount]),
yourdata[Year] = SELECTEDVALUE(driver[Year]))

 

Add Matrix visual 

speedramps_4-1737303010358.png

 

Change the row text colour to white

and change the Rows filedname to a single space

to hide it

speedramps_5-1737303118526.pngspeedramps_6-1737303173730.png

user the Driver year and not yourdate year in the slicer ... otherwise the solutoion will not work

speedramps_7-1737303376121.png

 

 

Please click [accept solution] and the thumbs up button. Thank you

Helpful resources

Announcements
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! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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