Power BI:在折线图图例中插入年和月

时间:2021-03-10 10:00:29

标签: powerbi

我在 powerBI 中有一个折线图,以过去 6 个月作为图例(2020 年 9 月至 2021 年 2 月)。问题是我希望按年份排序月份(2020 年 9 月、2020 年 10 月....2021 年 1 月、2021 年 2 月),但我无法在图例中同时插入年份和月份,它只接受以下一项他们:

enter image description here enter image description here

我尝试在编辑查询部分创建一个新列,该列从“Create_date”日期列中提取值(年-月)。但是当我在图例中插入此列时,它会从我的所有数据中获取所有值,而不是过去 6 个月。我拥有的日期过滤器用于原始的“create_date”列。

enter image description here

1 个答案:

答案 0 :(得分:2)

一种方法是通过为您计算图例的 Power Query Editor 添加一个新列。也许还有另一种时髦的方式,但这就是我的处理方式。

列有以下功能

= Table.AddColumn(#"Expanded Content", "Date For Legend", 
  each Number.ToText(Date.Year([Timestamp])) & 
       "-" & 
       Text.PadStart(Number.ToText(Date.Month([Timestamp])), 2, "0") & 
       " " & 
       Date.MonthName([Timestamp])
  )

这基本上采用了我的名为 [Tmestamp] 的列,并将其格式化为字符串字段以供我的图例使用。请注意,2020-09 出现在 2021-01 之前,一切正常。

Power BI

然后将折线图上的图例值改为Date For Legend

enter image description here enter image description here