power bi排序_如何在Power BI中按时间顺序对月份进行排序

本文介绍了如何在Power BI中正确排序月份,以便按照时间而非字母顺序展示销售数据等时间序列趋势。通过创建虚拟日期列并转换数据类型,然后使用MonthNumber字段进行排序,可以解决导入数据时月份排序错误的问题。
摘要由CSDN通过智能技术生成

power bi排序

In this article, I’m going to demonstrate how to sort months chronologically in Power BI. Visualizing sales data in a time period is one of the most influential ways of reporting. Often, at times it is essential that you design charts that show the trend or growth of a metric over time. The time period can be anything for example days, weeks, months, or years. It basically gives you the idea of how the metric has increased or decreased over the specific period.

在本文中,我将演示如何在Power BI中按时间顺序对月份进行排序。 可视化一段时间内的销售数据是最有影响力的报告方式之一。 通常,有时必须设计图表以显示度量标准随时间的趋势或增长。 时间段可以是任何时间,例如几天,几周,几个月或几年。 基本上,您可以了解指标在特定时期内如何增加或减少。

In Power BI, you can also visualize your metrics by a specific selected period. This is usually implemented by drawing line charts that show the trend over time, or by using vertical bar charts that show specific metrics in the time period, or even simply using a tabular matrix to display the results textually. For the sake of this article, we will consider only the third scenario i.e. tabular matrix for simplicity. However, the same solution can be made to work for any type of chart which contains a time period in it.

在Power BI中,您还可以按特定的选定时期可视化指标。 这通常是通过绘制显示随时间变化趋势的折线图,或使用显示时间段内特定指标的垂直条形图,甚至只是使用表格矩阵以文本形式显示结果来实现的。 为了本文的目的,为了简单起见,我们将仅考虑第三种情况,即表格矩阵。 但是,对于包含时间段的任何类型的图表,都可以使用相同的解决方案。

Sometimes when you import data into Power BI, and specifically if you have months or quarters available as a textual data in the original data source (from a flat-file), then Power BI cannot understand whether the imported field is an actual date field (days/month/year, etc.) or just simple text data. In such a case, after the import, the months or quarters are sorted alphabetically, rather than chronologically which is an error depending on the requirements and something not so relevant in developing trend reports. In this solution, we will first learn how to reproduce the error, and then see how to make the necessary changes in the data model to resolve this error and sort months chronologically in Power BI.

有时,当您将数据导入Power BI时,特别是如果原始数据源( 来自平面文件 )中的文本数据可用于月份或季度,则Power BI无法理解导入的字段是否为实际日期字段(天/月/年等)或仅是简单的文本数据。 在这种情况下,导入后,将按字母顺序而不是按时间顺序对月份或季度进行排序,这是一个错误,具体取决于需求以及与开发趋势报告无关的东西。 在此解决方案中,我们将首先学习如何重现错误,然后了解如何在数据模型中进行必要的更改以解决此错误并在Power BI中按月顺序排序。

重现错误 (Reproducing the Error)

Let us first try to reproduce the error and then I shall explain how to sort the months chronologically in Power BI. In order to replicate the error, we need to create a simple CSV file as shown in the figure below.

让我们首先尝试重现该错误,然后我将解释如何在Power BI中按时间顺序对月份进行排序。 为了复制错误,我们需要创建一个简单的CSV文件,如下图所示。

Sample Dataset for Sort Months Chronologically in Power BI

Figure 1 – CSV Dataset

图1 – CSV数据集

As you can see in the figure above, we just have two simple columns – Month and Sales. The Month lists all the values starting from “January” to “December” and corresponding Sales values along with it. Once you have created the CSV file, the next step is to open Power BI and connect it to this dataset.

如上图所示,我们只有两个简单的列-MonthSales本月列出了从“一月”到“十二月”开始的所有值以及相应的销售值。 创建CSV文件后,下一步是打开Power BI并将其连接到此数据集。

Open Power BI Desktop and follow the steps below to fetch this data into the Power BI data model:

打开Power BI Desktop,然后按照以下步骤将这些数据提取到Power BI数据模型中:

  1. Select on Get Data and select Text/CSV from the menu that appears

    选择获取数据,然后从出现的菜单中选择文本/ CSV

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值