Forum Discussion

letizia's avatar
letizia
Frequent Visitor
2 years ago
Solved

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.  

12 Replies

    • letizia's avatar
      letizia
      Frequent Visitor

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

      • danextian's avatar
        danextian
        Super User

        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.

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

    • letizia's avatar
      letizia
      Frequent Visitor

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

      • Ahmedx's avatar
        Ahmedx
        Super User

        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

  • 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".