Search code examples
powerbidax

a list on the axis messed up in power BI


I have a column it is supposed to be like

$0 - $4,000
$4,001 - $8,000
$8,001 - $12,000
$12,001 - $16,000
$16,001 - $20,000
$20,001 - $24,000
$24,001 - $28,000
$28,001 - $32,000
$32,001 - $36,000
$36,001 - $40,000
$40,001 - $44,000
$44,001 - $48,000
$48,001 AND OVER

but in Power BI, it is totally messed up as below. It is so frustrating. there are different years, some years this list is slight different. for example, in some year, the highest is $32,000 and OVER. I think it is the reason.

I hope someone can help me out.

Thanks. enter image description here


Solution

  • Power BI sorts text strings alphabetically by default, which is why your ranges are not appearing in the correct numerical order and to avoid circular dependency you can create a new table with explicit sort keys :

    Range Sort Table = 
    DATATABLE(
        "Range", STRING,
        "SortKey", INTEGER,
        {
            {"$0 - $4,000", 1},
            {"$4,001 - $8,000", 2},
            {"$8,001 - $12,000", 3},
            {"$12,001 - $16,000", 4},
            {"$16,001 - $20,000", 5},
            {"$20,001 - $24,000", 6},
            {"$24,001 - $28,000", 7},
            {"$28,001 - $32,000", 8},
            {"$32,001 - $36,000", 9},
            {"$36,001 - $40,000", 10},
            {"$40,001 - $44,000", 11},
            {"$44,001 - $48,000", 12},
            {"$48,001 AND OVER", 13}
        }
    )
    

    Then you sort Range column by the SortKey :

    enter image description here

    Then you link this table to your original one :

    enter image description here

    And you can use it in your visual like below :

    enter image description here