Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Sort with DAX Function FORMAT

Hello All.

 

Does anyone know when the bug will be fixed for sorting measure values that have the FORMAT() function applied to them?

 

12 Replies

  • In case you have created a measure like

    Month year = format(Date[date],"MMM-YYYY") which is text and not take date sorting anymore

    create a measure like

    Month year Sort= format(Date[date],"YYYYMM") and mark it as sort column

     

     

  • This is not actually a bug. When you call the FORMAT function you are converting the number to a string.

     

    When you sort values like 1,2,4,22 as strings

     

    It will sort as "1","2","22","4" with all the "numbers" that start with the same digit grouped together.

     

    If you can, you need to apply the formatting by setting the format property on the measure.

     

    However this will only work if you have a static format, if you are trying to dynamically change the format based on some sort of logical expression then you should vote for the idea on ideas.powerbi.com to add support for calculation groups to Power BI desktop as this functionality would let the engine apply formatting dynamically without using the FORMAT function.

     

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Wait, what bug is that? FORMAT changes things to text. So if for some reason you are trying to sort something in numerical order that would be a problem. Not certain if that is a bug.

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you all for the responses.

       

      I have a switch that goes bewteen Count and Sum. 

       

      when I format for currency it wont sort 😞

       

      Switch (Customer Value) = SWITCH(MAX('(Switch) KPI'[ID]),1,[Switch (Count)],2,FORMAT([Customer (Total Sales)],"$#,##0.00"))

       

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous,

        I'd like to suggest you create a calculated column and setting 'sort by column' property to use the original numeric field as sort order, it can fix the 'sorting issue' text value sorting order.

        In addition, you can also try to use the table properties formatting feature to change your measure format instead of use format function, this feature does not change the type of formula result.

        Regards,

        Xiaoxin Sheng