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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
letizia
Frequent Visitor

sorting

Hello, I have a formatted measure (so a text) which I want to sort by numerical value. My issue is that I have both negative and positive value, so even if I try to use 'UNICHAR' method adding "0" and then sort them, this doesn't work because of negative values. Any ideas? Thanks in advance.  

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hello,

Instead of using the FORMAT function which returns text, have you tried dynamic format strings?

https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-dynamic-format-strings 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

12 REPLIES 12
achandelkar6
New Member

NumericalSort =
VAR NumericValue =
IF(
LEFT([FormattedMeasure], 1) = "-",
-1 * VALUE(SUBSTITUTE([FormattedMeasure], "-", "")),
VALUE([FormattedMeasure])
)
RETURN
UNICHAR(8203) & TEXT(NumericValue, "0")


UNICHAR (8203) & TEXT(NumericValue, "0") - This section adds a zero-width space using UNICHAR(8203) to ensure proper sorting. The numerical value is then converted back to text using the Text function with a specified format of "0".

Ahmedx
Super User
Super User

show me what you write, what doesn’t work for you, at least share screenshots

sorting test.png

Here, from left to right: what I want to sort, measure I use, measure I'm trying to apply

Insert this measure before positive numbers
REP(UNICHAR(8203),x).
and where are the negatives after them.
for example:
REP(UNICHAR(8203),x)&[positive]
[nigativ]&REP(UNICHAR(8203),x)
X is how many times to repeat

Thanks but doesn't work because sorting depends from the total length of the string, no matter where 'unichar' is

Can you share a file and example that would be similar to your senario?

 

danextian
Super User
Super User

Hello,

Instead of using the FORMAT function which returns text, have you tried dynamic format strings?

https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-dynamic-format-strings 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hello ,thanks but I don't understand: does dynamic format string allows to treat measure as number and not as text?

Hi @letizia ,

with dynamic format string you are basically applying a format to a number but not changing its data type so it will still be treated as a number that just appears in either in percentage, currency, etc.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hello, how can I manage blank rows using dynamic format strings? Here is like blank rows are considered as zero in sorting, and I don't want that. I want blank rows at the end (or at the beginning) sorting test.png

Hello, thank you, it works.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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