power bi 中计算_Power BI中的期间比较

power bi 中计算

Just recently, I’ve come across a question on the LinkedIn platform, if it’s possible to create the following visualization in Power BI:

就在最近,我是否在LinkedIn平台上遇到了一个问题,是否有可能在Power BI中创建以下可视化文件:

Image for post

Since one of the common business requests is to perform different comparisons between various time periods, I would say that Power BI has a lot to offer in this regard. I’ve already explained some basic calculations related to Time Intelligence, but there are obviously a significant number of users who are not quite familiar with them.

由于常见的业务请求之一是在不同时间段之间执行不同的比较,因此我想说Power BI在这方面可以提供很多帮助。 我已经解释了一些与时间智能有关的基本计算方法 ,但是显然有很多用户对它们不太熟悉。

First of all, I would like to emphasize a great feature called “Quick Measures”, where you get out-of-the-box solutions for multiple commonly used calculations, such as: Year-to-date total, Quarter-to-date total, Month-to-date total, Year-over-year change, Rolling Average, etc.

首先,我想强调一个称为“快速度量”的出色功能,在该功能中,您将获得针对多种常用计算的开箱即用解决方案,例如:年初至今总计,季度初至今总数,本月至今的总数,同比变化,滚动平均值等。

In order for Quick Measures to work, you need to have a properly defined Date table.

为了使“快速度量”起作用,您需要具有正确定义的“ 日期”表 。

However, we will not use Quick Measures here to achieve our original goal, so let’s switch over to a Power BI Desktop and get into the action! As usual, I will use the Contoso database for demo purposes.

但是,在这里我们不会使用“快速测量”来实现我们的原始目标,因此让我们切换到Power BI Desktop并开始行动吧! 和往常一样,我将使用Contoso数据库进行演示。

制定基本措施 (Creating base measures)

The first step is to create a base measure to calculate Sales Amount:

第一步是创建一个基本度量来计算销售金额:

Sales Amt = SUM(FactOnlineSales[SalesAmount])

I will straight away create another measure, which will calculate same figures, but shifting one month back:

我将立即创建另一个度量,该度量将计算相同的数字,但将其移回一个月:

Sales Amt PM = CALCULATE([Sales Amt],
DATEADD(DimDate[Datekey],-1,MONTH)
)

There are multiple different ways to calculate this measure, but I prefer using DATEADD() function since it gives me more flexibility with shifting periods (that’s an official excuse:)…In reality, I’m coming from the SQL world, where DATEADD() is one of the most important functions when working with dates).

有多种不同的方法来计算此度量,但是我更喜欢使用DATEADD()函数,因为它为我提供了更灵活的移位周期(这是官方的借口:)……实际上,我来自SQL世界,其中DATEADD( )是处理日期时最重要的功能之一)。

Now, when I choose dates between November 17th and December 17th, I can see how my numbers correlate between themselves:

现在,当我选择11月17日至12月17日之间的日期时,可以看到我的数字之间的相互关系:

Image for post

As you may notice, our formulas work well — as intended, we see that Sales Amt PM for December 17th, matches Sales Amt for November 17th. Also, our Line chart nicely visualizes trends for easier comparison, while Card visuals in the upper left corner show Sales Amount for the selected period and difference between two periods which we are comparing.

您可能会注意到,我们的公式运行良好-按预期,我们看到12月17日的Sales Amt PM与11月17日的Sales Amt相匹配。 同样,我们的折线图很好地可视化了趋势,以便于比较,而左上角的卡片视觉效果则显示了所选期间的销售额和我们正在比较的两个期间之间的差异。

For those differences, I’ve created two additional measures:

对于这些差异,我创建了两个附加度量:

Sales Amt Diff PM = [Sales Amt] - [Sales Amt PM]
Sales Amt Diff PM % = DIVIDE([Sales Amt],[Sales Amt PM],BLANK()) - 1

Lower Card is conditionally formatted based on the values, so it goes red when we are performing worse than in the previous period, while it shows green when the outcome is the opposite:

Lower Card是根据值有条件格式化的,因此当我们的表现比上一时期差时,它会变成红色,而当结果相反时,它会变成绿色:

Image for post

添加更多成分 (Adding more ingredients)

Now, that’s fine and you saw how we could easily answer the original question. However, I wanted to add some more ingredients here and enable our users to choose between MoM (Month-over-month) and YoY (Year-over-year) comparison.

现在,这很好,您看到了我们如何轻松回答原始问题。 但是,我想在此处添加更多成分,并使我们的用户可以在MoM(按月)和同比(按年)比较之间进行选择。

In our example, if we choose again dates between November 17th and December 17th, instead of showing me values from the previous month (comparing December 17th and November 17th), with YoY comparison I want to compare December 17th 2009 with December 17th 2008!

在我们的示例中,如果我们再次选择11月17日至12月17日之间的日期,而不是显示上个月的值(与12月17日和11月17日相比),那么,我想将2009年12月17日与2008年12月17日进行比较!

So, let’s create a measure for this. Again, you can use different functions to achieve this, like SAMEPERIODLASTYEAR() function, but I want to keep consistency and therefore I will again use DATEADD():

因此,让我们为此制定一个措施。 同样,您可以使用不同的函数来实现这一点,例如SAMEPERIODLASTYEAR()函数,但是我想保持一致性,因此我将再次使用DATEADD():

Sales Amt PY = CALCULATE([Sales Amt],
DATEADD(DimDate[Datekey],-1,YEAR)
)

Same as for MoM calculations, two additional measures are needed to calculate differences for YoY figures:

与MoM计算相同,需要另外两项措施来计算同比数据差异:

Sales Amt Diff PY = [Sales Amt] - [Sales Amt PY]
Sales Amt Diff PY % = DIVIDE([Sales Amt],[Sales Amt PY],BLANK()) - 1

I will then create two bookmarks, so that users can navigate to MoM or YoY, by clicking on respective buttons:

然后,我将创建两个书签,以便用户可以通过单击相应的按钮来导航至MoM或YoY:

Image for post

By default, they should see MoM comparison, but as soon as they click on YoY button, the report will look slightly different:

默认情况下,他们应该看到MoM比较,但是一旦他们点击“同比”按钮,报告就会看起来有些不同:

Image for post

You can notice that numbers in the card visuals changed to reflect YoY difference calculation, while Line chart also shows different trends!

您会注意到,卡片视觉效果中的数字已更改为反映同比差异计算,而折线图也显示了不同的趋势!

Before we conclude, here is the final behavior of our report:

在得出结论之前,这是我们报告的最终行为:

Image for post

结论 (Conclusion)

As we saw, Power BI is quite a powerful tool when it comes to time intelligence calculations. Basically, all kinds of comparisons between different periods can be created — most common ones even without needing to write a single line of DAX!

如我们所见,在时间智能计算方面,Power BI是一个功能强大的工具。 基本上,可以创建不同时期之间的各种比较-即使不需要编写DAX行,也可以进行最常见的比较!

If you need to expand on built-in Quick Measures, there is a whole range of useful Time Intelligence functions. You can check all of them in more depth here.

如果您需要扩展内置的“快速测量”,则有很多有用的时间智能功能。 您可以在此处更深入地检查它们。

Thanks for reading!

谢谢阅读!

翻译自: https://towardsdatascience.com/period-comparisons-in-power-bi-7cc46705d663

power bi 中计算

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/390757.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

-Hive-

Hive定义 Hive 是一种数据仓库技术,用于查询和管理存储在分布式环境下的大数据集。构建于Hadoop的HDFS和MapReduce上,用于管理和查询分析结构化/非结构化数据的数据仓库; 使用HQL(类SQL语句)作为查询接口;使用HDFS作…

CentOS 7 安装 JDK

2019独角兽企业重金招聘Python工程师标准>>> 1、下载oracle jdk 下载地址: http://www.oracle.com/technetwork/java/javase/downloads/index.html 选择同一协议,下载rpm格式版本jdk,或tar.gz格式jdk。 2、卸载本机openjdk 2.1、查…

javascript 布尔_JavaScript布尔说明-如何在JavaScript中使用布尔

javascript 布尔布尔型 (Boolean) Booleans are a primitive datatype commonly used in computer programming languages. By definition, a boolean has two possible values: true or false.布尔值是计算机编程语言中常用的原始数据类型。 根据定义,布尔值有两个…

如何进行数据分析统计_对您不了解的数据集进行统计分析

如何进行数据分析统计Recently, I took the opportunity to work on a competition held by Wells Fargo (Mindsumo). The dataset provided was just a bunch of numbers in various columns with no indication of what the data might be. I always thought that the analys…

经典:区间dp-合并石子

题目链接 :http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid737 这个动态规划的思是,要得出合并n堆石子的最优答案可以从小到大枚举所有石子合并的最优情况,例如要合并5堆石子就可以从,最优的23和14中得到最佳的答案。从两堆…

常见排序算法_解释的算法-它们是什么以及常见的排序算法

常见排序算法In its most basic form, an algorithm is a set of detailed step-by-step instructions to complete a task. For example, an algorithm to make coffee in a french press would be:在最基本的形式中,算法是一组完成任务的详细分步说明。 例如&…

020-Spring Boot 监控和度量

一、概述 通过配置使用actuator查看监控和度量信息 二、使用 2.1、建立web项目&#xff0c;增加pom <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency> 启动项目&a…

matplotlib布局_Matplotlib多列,行跨度布局

matplotlib布局For Visualization in Python, Matplotlib library has been the workhorse for quite some time now. It has held its own even after more nimble rivals with easier code interface and capabilities like seaborn, plotly, bokeh etc. have arrived on the…

Hadoop生态系统

大数据架构-Lambda Lambda架构由Storm的作者Nathan Marz提出。旨在设计出一个能满足实时大数据系统关键特性的架构&#xff0c;具有高容错、低延时和可扩展等特性。Lambda架构整合离线计算和实时计算&#xff0c;融合不可变性&#xff08;Immutability&#xff09;&#xff0c…

javascript之 原生document.querySelector和querySelectorAll方法

querySelector和querySelectorAll是W3C提供的 新的查询接口&#xff0c;其主要特点如下&#xff1a; 1、querySelector只返回匹配的第一个元素&#xff0c;如果没有匹配项&#xff0c;返回null。 2、querySelectorAll返回匹配的元素集合&#xff0c;如果没有匹配项&#xff0c;…

RDBMS数据定时采集到HDFS

[toc] RDBMS数据定时采集到HDFS 前言 其实并不难&#xff0c;就是使用sqoop定时从MySQL中导入到HDFS中&#xff0c;主要是sqoop命令的使用和Linux脚本的操作这些知识。 场景 在我们的场景中&#xff0c;需要每天将数据库中新增的用户数据采集到HDFS中&#xff0c;数据库中有tim…

单词嵌入_神秘的文本分类:单词嵌入简介

单词嵌入Natural language processing (NLP) is an old science that started in the 1950s. The Georgetown IBM experiment in 1954 was a big step towards a fully automated text translation. More than 60 Russian sentences were translated into English using simple…

使用Hadoop所需要的一些Linux基础

Linux 概念 Linux 是一个类Unix操作系统&#xff0c;是 Unix 的一种&#xff0c;它 控制整个系统基本服务的核心程序 (kernel) 是由 Linus 带头开发出来的&#xff0c;「Linux」这个名称便是以 「Linus’s unix」来命名的。 Linux泛指一类操作系统&#xff0c;具体的版本有&a…

python多项式回归_Python从头开始的多项式回归

python多项式回归Polynomial regression in an improved version of linear regression. If you know linear regression, it will be simple for you. If not, I will explain the formulas here in this article. There are other advanced and more efficient machine learn…

《Linux命令行与shell脚本编程大全 第3版》Linux命令行---4

以下为阅读《Linux命令行与shell脚本编程大全 第3版》的读书笔记&#xff0c;为了方便记录&#xff0c;特地与书的内容保持同步&#xff0c;特意做成一节一次随笔&#xff0c;特记录如下&#xff1a; 《Linux命令行与shell脚本编程大全 第3版》Linux命令行--- Linux命令行与she…

彻底搞懂 JS 中 this 机制

彻底搞懂 JS 中 this 机制 摘要&#xff1a;本文属于原创&#xff0c;欢迎转载&#xff0c;转载请保留出处&#xff1a;https://github.com/jasonGeng88/blog 目录 this 是什么this 的四种绑定规则绑定规则的优先级绑定例外扩展&#xff1a;箭头函数this 是什么 理解this之前&a…

⚡如何在2分钟内将GraphQL服务器添加到RESTful Express.js API

You can get a lot done in 2 minutes, like microwaving popcorn, sending a text message, eating a cupcake, and hooking up a GraphQL server.您可以在2分钟内完成很多工作&#xff0c;例如微波炉爆米花&#xff0c;发送短信&#xff0c; 吃蛋糕以及连接GraphQL服务器 。 …

leetcode 1744. 你能在你最喜欢的那天吃到你最喜欢的糖果吗?

给你一个下标从 0 开始的正整数数组 candiesCount &#xff0c;其中 candiesCount[i] 表示你拥有的第 i 类糖果的数目。同时给你一个二维数组 queries &#xff0c;其中 queries[i] [favoriteTypei, favoriteDayi, dailyCapi] 。 你按照如下规则进行一场游戏&#xff1a; 你…

回归分析_回归

回归分析Machine learning algorithms are not your regular algorithms that we may be used to because they are often described by a combination of some complex statistics and mathematics. Since it is very important to understand the background of any algorith…

ruby nil_Ruby中的数据类型-True,False和Nil用示例解释

ruby niltrue, false, and nil are special built-in data types in Ruby. Each of these keywords evaluates to an object that is the sole instance of its respective class.true &#xff0c; false和nil是Ruby中的特殊内置数据类型。 这些关键字中的每一个都求值为一个对…