简体   繁体   English

Power Bi 中的列不按顺序排列

[英]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_Category分类的列仅包含 2016、2017、2018、2019 和 2020 年。SQL 代码如下

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.问题是,当我在 Power Bi 设计器中拖动Year_Category时,Year_Category 不像下图那样按顺序排列。

powerbi image powerbi 图像

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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