power bi函数

Aggregate functions are one of the main building blocks in Power BI. Being used explicitly in measures, or implicitly defined by Power BI, there is no single Power BI report which doesn’t use some sort of aggregate functions.

聚合功能是Power BI中的主要构建块之一。 由于在度量中显式使用或由Power BI隐式定义,因此没有单个Power BI报告不使用某种聚合函数。

聚合函数是什么? (What are the aggregate functions?)

Aggregating means combining values in your data performing some mathematical operation. That can be SUM, AVERAGE, MAXIMUM, MINIMUM, COUNT, COUNT DISTINCT, MEAN, STANDARD DEVIATION, etc.

汇总是指将数据中的值组合起来以执行一些数学运算。 可以是SUM,AVERAGE,MAXIMUM,MINIMUM,COUNT,COUNT DISTINCT,MEAN,标准偏差等。

However, in-depth observation of aggregate functions is not in the scope of this article. Here, I wanted to demonstrate how you can use aggregate functions in an unconventional way, since I believe it can be useful in some specific scenarios.

但是,对聚合函数的深入观察不在本文的范围之内。 在这里,我想演示如何以一种非常规的方式使用聚合函数,因为我认为它在某些特定情况下很有用。

聚合函数的默认行为 (Default behavior of aggregate functions)

By default, aggregations are being calculated on columns. Let’s take a look at following basic example:

默认情况下,聚合是在列上计算的。 让我们看下面的基本示例:

This is a typical example of SUM aggregate function. Numbers are being aggregated on Year and Month level, and finally, in the end, we can see the total of individual values in the table.

这是SUM聚合函数的典型示例。 数字在“年”和“月”级别上进行汇总,最后,最后,我们可以在表中看到各个值的总数。

We could also perform AVERAGE to find average values, MIN or MAX to find the minimum and maximum values, etc. Pretty straightforward and probably already known for most of the people who ever worked with Power BI or Excel.

我们还可以执行AVERAGE来查找平均值,使用MIN或MAX来查找最小值和最大值,等等。这非常简单,对于使用Power BI或Excel的大多数人来说可能已经众所周知。

行上的聚合-毫不动摇! (Aggregation on rows — without unpivoting!)

But, what if we wanted to perform aggregations on rows instead of columns? Is it possible to do that? And if yes, how?

但是,如果我们想对行而不是对列执行聚合呢? 有可能这样做吗? 如果是的话,怎么办?

Let’s head over to a Power BI and check immediately. I have an Excel file as a data source and a dummy table which contains data about the customer and first date within a single year when he made a purchase:

让我们转到Power BI并立即检查。 我有一个Excel文件作为数据源,还有一个虚拟表,其中包含有关客户和他在购买后一年内的首次约会的数据:

As you can see, some customers made a purchase in every single year, some have gaps, some came in later years, etc.

如您所见,有些客户每年都进行购买,有些客户有缺口,有些则是在以后几年等等。

Now, I want to retrieve the earliest date when a customer made a purchase, so I can later perform analysis based on that date (for example, to analyze how many customers made first purchase in February 2017).

现在,我想检索客户进行购买的最早日期,以便稍后可以基于该日期进行分析(例如,分析在2017年2月进行首次购买的客户数量)。

I know, most of you would probably go with Power Query transformation and Unpivoting years’ columns, something like this:

我知道,你们中的大多数人可能会使用Power Query转换和Unpivoting年的列,如下所示:

And you get a nice new look of the table, with all dates grouped by customer:

您会看到表格的新外观,所有日期均按客户分组:

However, an additional workload is necessary to build a separate column which will hold data about the earliest date (or MIN date) for every single customer, so we can later use this column for filtering purposes, or even for building a relationship to a date dimension.

但是,需要额外的工作量来构建一个单独的列,该列将保存有关每个客户的最早日期(或MIN日期)的数据,因此我们以后可以将该列用于过滤目的,甚至建立与日期的关系。 尺寸 。

What if I tell you that you can do this with a single line of code and without any additional transformations?

如果我告诉您可以用一行代码执行而无需任何其他转换,该怎么办?

First, I will close the Power Query editor and go straight to the Power BI Data view:

首先,我将关闭Power Query编辑器并直接进入Power BI Data视图:

You see that this table looks exactly the same as in Excel. Now, I choose to create a new column and, when prompted, enter following DAX code:

您会看到此表看起来与Excel中的表完全相同。 现在,我选择创建一个新列,并在出现提示时输入以下DAX代码:

First Purchase Date = MINX({Sheet2[2016],Sheet2[2017],Sheet2[2018],Sheet2[2019]},[Value])

Let’s stop here for the moment and explain what we are doing. So, we want to extract the minimum date from every single row. We could do that by using multiple nested IF statements and using MIN aggregate function. Since MIN function accepts only two arguments, we would have multiple levels of nested IF statements, which is quite ugly and pretty much hardly readable.

让我们暂时在这里停止并解释我们在做什么。 因此,我们要从每一行中提取最小日期。 我们可以通过使用多个嵌套的IF语句并使用MIN聚合函数来做到这一点。 由于MIN函数仅接受两个参数,因此我们将具有多层嵌套的IF语句,这很难看而且很难读。

The magic here is in the curly brackets! By using them, we are telling DAX that we want it to create a table from the list within the curly brackets, and using MINX iterator aggregate function, we are simply iterating through this table and pulling minimum value from it.

魔术在花括号中! 通过使用它们,我们告诉DAX我们希望它在大括号内的列表中创建一个表,并使用MINX迭代器聚合函数,我们仅在该表中进行迭代并从中获取最小值。

How cool and elegant is that! It worked like a charm and here is the resulting column:

那是多么的酷和优雅! 它像一种魅力一样工作,这是结果列:

You can easily spot that DAX returned expected values, so now we can use this column as an axis in our charts, create regular date hierarchies on it, or we can even create a relationship between First Purchase Date and date dimension in our data model if we like to.

您可以轻松地发现DAX返回了期望值,因此现在我们可以将该列用作图表中的轴,在其上创建常规的日期层次结构,或者在以下情况下甚至可以在数据模型中的“首次购买日期”和日期维度之间建立关系:我们喜欢。

结论 (Conclusion)

Power BI and DAX are full of hidden gems. In complete honesty, I have to admit that you might not face a scenario like this every single day, but in some specific situations, it’s good to know that you can perform aggregate functions on row level in a very simple, yet powerful manner — using a literally single line of code!

Power BI和DAX充满了隐藏的宝石。 老实说,我必须承认您可能不会每天都遇到这样的情况,但是在某些特定情况下,很高兴知道您可以以非常简单但功能强大的方式在行级别执行聚合函数-使用真正的单行代码!

翻译自: https://towardsdatascience.com/use-aggregate-functions-on-rows-in-power-bi-904724a54374

power bi函数


http://www.taodudu.cc/news/show-994864.html

相关文章:

  • 大数定理 中心极限定理_中心极限定理:直观的遍历
  • 探索性数据分析(EDA)-不要问如何,不要问什么
  • 安卓代码还是xml绘制页面_我们应该绘制实际还是预测,预测还是实际还是无关紧要?
  • 云尚制片管理系统_电影制片厂的未来
  • t-sne原理解释_T-SNE解释-数学与直觉
  • js合并同类数组里面的对象_通过同类群组保留估算客户生命周期价值
  • com编程创建快捷方式中文_如何以编程方式为博客创建wordcloud?
  • 基于plotly数据可视化_如何使用Plotly进行数据可视化
  • 用Python创建漂亮的交互式可视化效果
  • php如何减缓gc_管理信息传播-使用数据科学减缓错误信息的传播
  • 泰坦尼克号 数据分析_第1部分:泰坦尼克号-数据分析基础
  • vba数组dim_NDArray — —一个基于Java的N-Dim数组工具包
  • python算法和数据结构_Python中的数据结构和算法
  • python dash_Dash是Databricks Spark后端的理想基于Python的前端
  • 在Python中查找子字符串索引的5种方法
  • 趣味数据故事_坏数据的好故事
  • python分句_Python循环中的分句,继续和其他子句
  • python数据建模数据集_Python中的数据集
  • usgs地震记录如何下载_用大叶草绘制USGS地震数据
  • 数据可视化 信息可视化_更好的数据可视化的8个技巧
  • sql 左联接 全联接_通过了解自我联接将您SQL技能提升到一个新的水平
  • 科学价值 社交关系 大数据_服务的价值:数据科学和用户体验研究美好生活
  • vs azure web_在Azure中迁移和自动化Chrome Web爬网程序的指南。
  • selenium 解析网页_用Selenium进行网页搜刮
  • hive 导入hdfs数据_将数据加载或导入运行在基于HDFS的数据湖之上的Hive表中的另一种方法。
  • 大数据业务学习笔记_学习业务成为一名出色的数据科学家
  • python 开发api_使用FastAPI和Python快速开发高性能API
  • Power BI:M与DAX以及度量与计算列
  • 梯度下降法优化目标函数_如何通过3个简单的步骤区分梯度下降目标函数
  • seaborn 子图_Seaborn FacetGrid:进一步完善子图

power bi函数_在Power BI中的行上使用聚合函数相关推荐

  1. java convert函数_自己实现 java中 Convert.toDouble(String str)处理函数 | 学步园

    今天在superWaba上看到Convert.toDouble(String str),由于底层问题比较大的数就出错,现在自己写了一个 程序中info()是我加的打印,可以去掉 java中 Conve ...

  2. python agg函数_个人对Pandas中agg、apply和transform函数的理解

    个人对Pandas中agg.apply和transform函数的理解 学习<利用Python进行数据分析>一书,关于pandas的这三个函数,个人理解如下. agg agg方法可以被gro ...

  3. stl string 函数_使用C ++ STL中的string :: append()函数将文本追加到字符串

    stl string 函数 append() is a library function of <string> header, it is used to append the extr ...

  4. python68个内置函数_直接在python中检索68个内置函数?

    Python3.5中的一种方法是列出具有__module__属性并将其设置为builtins和小写名称的对象:>>> sorted(k for k, v in vars(__buil ...

  5. MYSQL中最基础的的聚合函数(重点!)

    一.聚合函数的介绍 在数据库查询过程中,不仅只返回数据的基础信息,有时还需对这些数据进行统计和汇总.MySQL 提供了聚合函数,用于实现这些高级功能. 二.聚合函数的基础运用 聚合函数用于对一组值进行 ...

  6. MySQL之创建函数,一次性插入表中多行数据

    MySQL之创建函数,一次性插入表中多行数据 一.MySQL之使用存储过程创建函数,一次性插入表中多行数据 一.MySQL之使用存储过程创建函数,一次性插入表中多行数据 #DELIMITER 的使用 ...

  7. main函数的参数详解,它们是何时何处传入的?(main函数的参数值是从操作系统命令行上获得的)

    一般的main函数都是不带参数的,因此main 后的括号都是空括号.实际上,main函数可以带参数,这个参数可以认为是 main函数的形式参数.C语言规定main函数的参数只能有两个, 习惯上这两个参 ...

  8. power bi 参数_参数化Power BI报表入门

    power bi 参数 In this article, I am going to explain how we can develop parameterized Power BI reports ...

  9. python中add函数_如何使用python中的add函数?

    之前向大家介绍过python中的求和函数sum函数,numpy中的sum函数,对于数组可以指定维度进行相加.numpy中还有另一种求和运算方法,即add函数.add函数不仅作用于numpy中加法运算, ...

最新文章

  1. leetcode Single Number python
  2. Shellcode开发辅助工具shellnoob
  3. 1-3月我国软件业务收入同比增长12.9%
  4. std::chrono时间库详解
  5. 编写 Servlet 2.3 Filter
  6. Spring Boot中使用log4j实现http请求日志入mongodb
  7. ffmpy3与ffmpeg的简单使用
  8. 浅谈equals和hashcode
  9. Bootstrap3 横向表单/水平表单
  10. Python中的字符串比较:与== [重复]
  11. 2015年全国村级点位置矢量SHP格式数据下载
  12. html链接安装包,磁力宅资源链接地址
  13. 苹果android投屏,iphone怎么投屏到mac?苹果手机投屏到苹果电脑方法
  14. 0.1 Typora 文档备份
  15. 基于高分辨率影像城市绿地信息提取_[转]ENVI支持下利用高分辨率影像城市绿地信息提取方案...
  16. 【杂记】全栈开发中碰到的一些问题及解决方法
  17. 企业邮箱发送出去的邮件找不到了
  18. 如何成为技术大牛(华为超级技术大牛的十年经验总结)
  19. 销售技巧之绕过前台的31法
  20. Linux多线程---线程概念和线程控制

热门文章

  1. c语言中 %.2s,C2S是什么意思
  2. waitpid()函数
  3. java环境变量怎么配置,详解系列文章
  4. 关于秒杀系统优化方向
  5. bitmap转换为drawable
  6. 基于ARM Cortex-M0+ 的Bootloader 参考
  7. java线程并发库之--线程同步工具CountDownLatch用法
  8. 判断一个图中有无环路的存在
  9. jQuery以JSONP的访问调用一个WCF REST服务
  10. RRDTool学习资料备忘