简体   繁体   English

Power BI:在 DAX 中按 YearMonth 排序数据

[英]Power BI: Order data by YearMonth in DAX

I would like to create a YearMonth column in Power BI and group data in this order in visual plot, say histogram.我想在 Power BI 中创建一个YearMonth列,并按此顺序在可视 plot 中对数据进行分组,例如直方图。

I tried to create a duplicate of the datetime column MY_DATE (format: 05-10-2018 12:00:00 AM ) and convert it to Year-Month format in the ColumnTools ribon:我尝试创建日期时间列MY_DATE的副本(格式:05-10-2018 05-10-2018 12:00:00 AM )并在ColumnTools其转换为Year-Month格式:

在此处输入图像描述

Although in the column the format looks correct, eg., '2018-03', when I plot the graph after grouping by YearMonth it is repeating itself, ie., having multiple columns of 2018-07 .尽管在列中格式看起来是正确的,例如“2018-03”,但当我 plot 按YearMonth分组后,它会重复自身,即具有多列2018-07

Then I tried creating YearMonth with:然后我尝试使用以下方法创建YearMonth

YearMonthText = YEAR(Table[MY_DATE]) & "-" & MONTH(Table[MY_DATE])

This looks good in both table column and was able to aggregate data when grouped by YearMonth , however, the table is not in chronological order, eg.:这在两个表列中看起来都不错,并且能够在按YearMonth分组时聚合数据,但是,该表不是按时间顺序排列的,例如:

2020-10   2020-11   2020-12   2020-7   2020-8   2020-9   2021-1   2021-2   ...

How can I get the plot to show data in chronological order?如何让 plot 按时间顺序显示数据?

Worked for me:为我工作:

First, use:首先,使用:

YearMonthText = YEAR(Table[MY_DATE]) & "-" & MONTH(Table[MY_DATE])

to get YearMonth in text format(eg., 2018-3 ).以文本格式获取YearMonth (例如2018-3 )。

Then, convert Data type to Date type in ColumnTools ribon.然后,在 ColumnTools ribon 中将Data type转换为Date类型。

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

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