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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
shalmali30
Regular Visitor

Multi column sort with Field parameter .

I want to sort 2 columns on select of slicer value which is filed parameter.

 

I have field parameter as below : 

Geo = {
    ("Region", NAMEOF('reportmain'[Region]), 0),
    ("SubRegion", NAMEOF('reportmain'[SubRegion]), 1),
    ("Unit", NAMEOF('reportmain'[Unit]), 2),
    ("Country", NAMEOF('reportmain'[Country]), 3)
}
 
I have a table visual with values : Geo (whatever is selected ), FY, Sum(Inventory). If I select Region from Slicer: The first column will be Region, FY,Sum(Inventory). I want to sort First column ASC and then FY desc. The sample data : 
Region FYInventory
CIS202423
CIS202334
EU202443
EU202321

 

If I select sub region : 

SubRegionFYInventory
ABC202412
ABC202322
QWE20242
QWE20232
Z20242

 

like wise for Unit and Country. I have created a column : 

SortColumnMeasure =
VAR SelectedGeo = SELECTEDVALUE(Geo[Geo Fields])  
RETURN
    SWITCH (
        TRUE(),
        SelectedGeo = "Region",
            Reportmain[Region] & "-" & FORMAT(Reportmain[year], "0000"),
        SelectedGeo = "Subregion",
            Reportmain[Region] & Reportmain[Subregion] & "-" & FORMAT(Reportmain[year], "0000"),
        SelectedGeo = "Unit",
            Reportmain[Region] & Reportmain[Subregion] & Reportmain[Unit] & "-" & FORMAT(Reportmain[year], "0000"),
        SelectedGeo = "Country",
            Reportmain[Region] & Reportmain[Subregion] & Reportmain[Unit] & Reportmain[Country] & "-" & FORMAT(Reportmain[year], "0000"),
        -- Default case
        reportmain[Region] & "-" & FORMAT(Reportmain[year], "0000") ) 
 
But above switch always takes the Default case. PLease suggest 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @shalmali30 ,

 

At the moment, there are no direct features to do this. I can provide a workaround, here are the steps:

Create a measure to generate the custom sort numbers.

 

Sort =
VAR _sel =
    SELECTEDVALUE ( Geo[Geo Fields] )
RETURN
    RANKX (
        ALLSELECTED ( 'Table' ),
        RANKX (
            ALLSELECTED ( 'Table' ),
            CALCULATE (
                SWITCH (
                    _sel,
                    "'Table'[Region]", MAX ( 'Table'[Region] ),
                    "'Table'[SubRegion]", MAX ( 'Table'[SubRegion] ),
                    "'Table'[Unit]", MAX ( 'Table'[Unit] ),
                    "'Table'[Country]", MAX ( 'Table'[Country] )
                )
            ),
            ,
            ASC,
            DENSE
        ) * 100
            + RANKX (
                ALLSELECTED ( 'Table' ),
                CALCULATE ( MAX ( 'Table'[FY] ) ),
                ,
                DESC,
                DENSE
            ),
        ,
        ASC,
        DENSE
    )

 

Put it in to the visual, when you select Subregion, the visual will be sorted in ascending order by region column, and then in descending order of FY.

vstephenmsft_1-1728637801977.png

 

 

 

Best Regards,

Stephen Tao

 

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

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @shalmali30 ,

 

At the moment, there are no direct features to do this. I can provide a workaround, here are the steps:

Create a measure to generate the custom sort numbers.

 

Sort =
VAR _sel =
    SELECTEDVALUE ( Geo[Geo Fields] )
RETURN
    RANKX (
        ALLSELECTED ( 'Table' ),
        RANKX (
            ALLSELECTED ( 'Table' ),
            CALCULATE (
                SWITCH (
                    _sel,
                    "'Table'[Region]", MAX ( 'Table'[Region] ),
                    "'Table'[SubRegion]", MAX ( 'Table'[SubRegion] ),
                    "'Table'[Unit]", MAX ( 'Table'[Unit] ),
                    "'Table'[Country]", MAX ( 'Table'[Country] )
                )
            ),
            ,
            ASC,
            DENSE
        ) * 100
            + RANKX (
                ALLSELECTED ( 'Table' ),
                CALCULATE ( MAX ( 'Table'[FY] ) ),
                ,
                DESC,
                DENSE
            ),
        ,
        ASC,
        DENSE
    )

 

Put it in to the visual, when you select Subregion, the visual will be sorted in ascending order by region column, and then in descending order of FY.

vstephenmsft_1-1728637801977.png

 

 

 

Best Regards,

Stephen Tao

 

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

 

shalmali30
Regular Visitor

@dharmendars007 ,I have done this already (added Sortcolumnmeasure in the visual and sort by  this column). This works perfectly fine if Region is selected as Region is in default case. If i select SubRegion from slicer, It still sorts by Region though the first column changes to SubRegion. so based on slicer selection, the sorting should be applied asc to first column and desc to FY (year). Can you please suggest over this ?

dharmendars007
Super User
Super User

Hello @shalmali30 , 

 

You can create a dynamic sort column based on the slicer selection. Since you're already using a field parameter for "Geo," you can extend the logic to control sorting behavior.

 

After creating this calculated measure (Sortcolumnmeasure), you need to set it as the sort column for your table.

 

Go to the visual where you want to apply the sort. Select the first column (like Region or SubRegion based on the slicer), and in the top menu (or in the ellipsis in the field pane), choose Sort by Column and select your calculated sort column (Sortcolumnmeasure)

 

SortColumnMeasure =
VAR SelectedGeo = SELECTEDVALUE(Geo[Geo Fields])
RETURN
SWITCH (
TRUE(),
SelectedGeo = "Region", Reportmain[Region] & "-" & FORMAT(Reportmain[Year], "0000") & "-" & FORMAT(Reportmain[Inventory], "000000"),
SelectedGeo = "SubRegion", Reportmain[SubRegion] & "-" & FORMAT(Reportmain[Year], "0000") & "-" & FORMAT(Reportmain[Inventory], "000000"),
SelectedGeo = "Unit", Reportmain[Unit] & "-" & FORMAT(Reportmain[Year], "0000") & "-" & FORMAT(Reportmain[Inventory], "000000"),
SelectedGeo = "Country", Reportmain[Country] & "-" & FORMAT(Reportmain[Year], "0000") & "-" & FORMAT(Reportmain[Inventory], "000000"),
Reportmain[Region] & "-" & FORMAT(Reportmain[Year], "0000") -- Default case, sorts by Region and Year)

 

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes 👍 are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

@dharmendars007 , Thanks. I have added that measure in the sort by. It works correct if Region is selected from the slicer. If I select Subregion from slicer, though the first column changes to subregion,  the data is sorted with the Region logic only. I want it to be sorted by subregion asc first and then FY year  Desc if Subregion is selected . (Sorting should happen based on the value selected from slicer)

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.