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

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

Reply
Anonymous
Not applicable

Sort the dynamic values in a text box

Hi everyone,

 

I have a a slicer in my dashboard and a text box to show all the values that are selected in the slicer or show 'All' if all values are selected. It is working fine and shows the correct selections except that they are not sorted. Is there any way to sort these dynamic values? I am kind of new to Power BI and have tried to look for some documentation on this with no luck so far.
Hence, any help would be highly appreciated. Thank you in advance for your time!

Here is the calculation I have used for the text box value:

Week Card : =
VAR _countrs =
    COUNTROWS(VALUES('Fiscal_Cal'[Week]))
var _countsall =
    CALCULATE(
            COUNTROWS(VALUES('Fiscal_Cal'[Week])), REMOVEFILTERS('Fiscal_Cal')
    )
    return
    if( _countrows = _countsall, "All",
    CALCULATE(CONCATENATEX(DISTINCT('Fiscal_Cal'[Week]), 'Fiscal_Cal'[Week], ", ")
    ))

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

To sort the dynamic values that are shown in the text box, you can use the SORT function to sort the list of values returned by the CONCATENATEX function. Here is an example of how you can modify your measure to achieve this:

Week Card : =
VAR _countrs =
    COUNTROWS(VALUES('Fiscal_Cal'[Week]))
var _countsall =
    CALCULATE(
            COUNTROWS(VALUES('Fiscal_Cal'[Week])), REMOVEFILTERS('Fiscal_Cal')
    )
    return
    if( _countrows = _countsall, "All",
    CALCULATE(
        CONCATENATEX(
            SORT(DISTINCT('Fiscal_Cal'[Week]), 'Fiscal_Cal'[Week], ASC),
            'Fiscal_Cal'[Week],
            ", "
        )
    ))

The SORT function takes in a table as the first argument, and then a list of columns to sort by as subsequent arguments. In this case, we are sorting the list of distinct weeks in ascending order. The ASC argument specifies that the sort order should be ascending. If you want to sort the values in descending order, you can use the DESC argument instead.


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

2 REPLIES 2
Anonymous
Not applicable

Hi @v-henryk-mstf,

 

Thank you for your reply with a detailed explaination. I tried your suggested approach and I ended up getting this error on the SORT function
Screenshot (9).png

v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

To sort the dynamic values that are shown in the text box, you can use the SORT function to sort the list of values returned by the CONCATENATEX function. Here is an example of how you can modify your measure to achieve this:

Week Card : =
VAR _countrs =
    COUNTROWS(VALUES('Fiscal_Cal'[Week]))
var _countsall =
    CALCULATE(
            COUNTROWS(VALUES('Fiscal_Cal'[Week])), REMOVEFILTERS('Fiscal_Cal')
    )
    return
    if( _countrows = _countsall, "All",
    CALCULATE(
        CONCATENATEX(
            SORT(DISTINCT('Fiscal_Cal'[Week]), 'Fiscal_Cal'[Week], ASC),
            'Fiscal_Cal'[Week],
            ", "
        )
    ))

The SORT function takes in a table as the first argument, and then a list of columns to sort by as subsequent arguments. In this case, we are sorting the list of distinct weeks in ascending order. The ASC argument specifies that the sort order should be ascending. If you want to sort the values in descending order, you can use the DESC argument instead.


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors