简体   繁体   中英

The Column not in sequence in Power Bi

The column I categorize using Case-When as Year_Category which consist only year 2016,2017,2018, 2019 and 2020. The SQL code as below

CASE WHEN Year(STARTED) = '2016' THEN '2016'
          WHEN Year(STARTED) = '2017' THEN '2017'
WHEN Year(STARTED) = '2018' THEN '2018'
WHEN Year(STARTED) = '2019' THEN '2019'
WHEN Year(STARTED) = '2017' THEN '2020'
END AS YEARS_CAT

The question is, when I drag the the Year_Category at Power Bi designer, the Year_Category not in sequence like image below.

powerbi image

Either convert that column into whole number or create another column that will act as a sorting column for Text Year column

Sample code that will help in sorting the column:

Text Year Sort =
VAR CurrentDate = Dates[Date] -- Date in the row context
VAR YearCurrentDate =
    YEAR ( CurrentDate )
VAR MaxDate =
    MAX ( Dates[Date] )
VAR MinDate =
    MIN ( Dates[Date] )
VAR YearMinDate =
    YEAR ( MinDate )
VAR YearMaxDate =
    YEAR ( MaxDate )
VAR YearGap = YearMaxDate - YearMinDate
VAR Result =
    1 + YearGap
        - ABS ( YearCurrentDate - YearMaxDate )
RETURN
    Result

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM