power bi中的切片器_在Power Bi中显示选定的切片器

power bi中的切片器

Just recently, while presenting my session: “Magnificent 7 — Simple tricks to boost your Power BI Development” at the New Stars of Data conference, one of the questions I’ve received was:

就在最近,在“新数据之星”会议上介绍我的会议: “壮丽的7 —促进Power BI开发的简单技巧”时,我收到的问题之一是:

根据页面上的切片器选择,是否可以显示实际的活动过滤器? (Is there a way to show the actual active filters as a result of the slicer choices on the page?)

I’ve already answered the question in this article, but then I thought: maybe more people search for the solution to this problem, so I decided to write a short post to explain in detail how you can achieve this.

我已经在本文中回答了这个问题,但是后来我想:也许更多的人正在寻找解决这个问题的方法,所以我决定写一篇简短的文章来详细说明如何实现此目的。

As usual, I will use a sample Contoso database for demo purposes:

和往常一样,我将使用示例Contoso数据库进行演示:

DAX是您的朋友! (DAX is your friend!)

Image for post

This is the starting point. You can notice three slicers on the report canvas, and let’s say that I want to show my users which brands are selected within Brands slicer.

这是起点。 您可以在报表画布上注意到三个切片器,并且假设我要向用户显示在“品牌”切片器中选择了哪些品牌。

The first step is to create a DAX measure that will capture all selected values in the slicer. You can use two different DAX functions to obtain the values: VALUES() or DISTINCT(). VALUES() function is more complex since you can use both table name and column name as an argument, but let’s focus here on the column name as an argument.

第一步是创建一个DAX度量,它将捕获切片器中的所有选定值。 您可以使用两个不同的DAX函数来获取值: VALUES()DISTINCT()VALUES()函数更加复杂,因为您可以将表名和列名都用作参数,但是在这里,我们将重点放在列名作为参数上。

Basically, VALUES() will return all distinct values from the column we passed, including blanks (if exist)! On the other hand, DISTINCT() will return all distinct values but ignoring blank values. Which one you want to use, depends mostly on the business request (if your users want to see numbers for blanks or not). Personally, I prefer to use VALUES(), because it gives me the full picture.

基本上, VALUES()将返回我们传递的列中的所有不同值,包括空格(如果存在)! 另一方面, DISTINCT()将返回所有不同的值,但忽略空白值。 您要使用哪一个,主要取决于业务请求(如果您的用户希望查看是否为空白的数字)。 就个人而言,我更喜欢使用VALUES() ,因为它可以给我完整的画面。

So, I will create the following measure:

因此,我将创建以下措施:

Selected Brands = VALUES('Product'[BrandName])

Now, when I put this measure in the Card visual, let’s see what happens:

现在,当我将此度量放入Card视觉中时,让我们看看会发生什么:

Image for post

Oops, that gives me an error! Error message explains that the calculation expects a single value. The problem is that VALUES() and DISTINCT() return TABLE! However, it’s not a “normal” table, it’s virtual table created on the fly by DAX engine, so we should apply some additional calculations in order to extract single values from it.

糟糕,这给了我一个错误! 错误消息说明计算需要单个值。 问题是VALUES()和DISTINCT()返回TABLE! 但是,它不是“普通”表,而是由DAX引擎动态创建的虚拟表,因此我们应该应用一些其他计算,以便从中提取单个值。

迭代器功能可以解救! (Iterator functions to the rescue!)

Iterator functions do what their name says — they iterate over the table and apply the calculation row by row! Iterator functions have X in the end: SUMX, AVERAGEX, COUNTX…In our scenario, we need to iterate over our distinct values and concatenate them into our string, which will be later displayed in the report. To achieve that, we will use CONCATENATEX() function.

迭代器函数按其名称所述执行操作-遍历表并逐行应用计算! 迭代器函数的末尾有X:SUMX,AVERAGEX,COUNTX…在我们的方案中,我们需要遍历不同的值并将它们连接到我们的字符串中,然后将其显示在报告中。 为此,我们将使用CONCATENATEX()函数。

This function accepts three arguments: the first is a table that we want to iterate on (in our case, a virtual table created using VALUES() function), then expression we are applying row by row on this table, and finally delimiter we want to use for separating extracted values.

该函数接受三个参数:第一个是要迭代的表(在本例中,是使用VALUES()函数创建的虚拟表),然后在表中逐行应用表达式,最后使用所需的定界符用于分离提取的值。

Selected Brands = CONCATENATEX(
VALUES('Product'[BrandName]),
'Product'[BrandName],
",")

In my example, I’m using comma as a delimiter, but you can also use others, such as a semicolon, etc. Now, when I look again in my report, I can see that I got desired results:

在我的示例中,我使用逗号作为定界符,但是您也可以使用其他字符,例如分号等。现在,当我再次查看报表时,可以看到获得了预期的结果:

Image for post

And, if I choose only few brands within the slicer, my card will adjust to reflect the changes:

而且,如果我在切片器中只选择了少数几个品牌,我的卡将进行调整以反映更改:

Image for post

结合多种措施 (Combining multiple measures)

You can create the same measure for other slicers also, and then put all the results in the table visual. So, I will create the measure for Year slicer:

您也可以为其他切片器创建相同的度量,然后将所有结果显示在表格中。 因此,我将为Year slicer创建度量:

Selected Year = CONCATENATEX(
VALUES(Dates[Year])
,Dates[Year]
,",")

Now, when I drag bit my measures into the table fields, I see both of my selected slicers’ values at one place:

现在,当我将度量值拖到表字段中时,我会在一个位置看到两个选择的切片器的值:

Image for post

奖励想法! (Bonus idea!)

If you have many slicers in your report, and you want to display all of the selections, but you don’t want to waste space on your report canvas, you can create a bookmark containing the table with all selected values, and then just display the bookmark on user’s request.

如果报表中有许多切片器,并且要显示所有选择,但又不想浪费报表画布上的空间,则可以创建一个包含表的书签,其中包含所有选定值,然后仅显示根据用户要求添加书签。

Something like this:

像这样:

Image for post

How cool is that! So, you don’t need to worry about bloating your report space with this table. You can show/hide it using bookmarks and actions.

多么酷啊! 因此,您不必担心使用此表会增加报告空间。 您可以使用书签和操作显示/隐藏它。

翻译自: https://towardsdatascience.com/display-selected-slicers-in-power-bi-a99d81500e76

power bi中的切片器

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

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

相关文章

5939. 半径为 k 的子数组平均值

5939. 半径为 k 的子数组平均值 给你一个下标从 0 开始的数组 nums ,数组中有 n 个整数,另给你一个整数 k 。 半径为 k 的子数组平均值 是指:nums 中一个以下标 i 为 中心 且 半径 为 k 的子数组中所有元素的平均值,即下标在 i …

数据库逻辑删除的sql语句_通过数据库的眼睛查询sql的逻辑流程

数据库逻辑删除的sql语句Structured Query Language (SQL) is famously known as the romance language of data. Even thinking of extracting the single correct answer from terabytes of relational data seems a little overwhelming. So understanding the logical flow…

数据挖掘流程_数据流挖掘

数据挖掘流程1-简介 (1- Introduction) The fact that the pace of technological change is at its peak, Silicon Valley is also introducing new challenges that need to be tackled via new and efficient ways. Continuous research is being carried out to improve th…

北门外的小吃街才是我的大学食堂

学校北门外的那些小吃摊,陪我度过了漫长的大学四年。 细数下来,我最怀念的是…… (1)烤鸡翅 吸引指数:★★★★★ 必杀技:酥流油 烤鸡翅有蜂蜜味、香辣味、孜然味……最爱店家独创的秘制鸡翅。鸡翅的外皮被…

[LeetCode]最长公共前缀(Longest Common Prefix)

题目描述 编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串 ""。 示例 1:输入: ["flower","flow","flight"]输出: "fl"示例 2:输入: ["dog","racecar",&quo…

spark的流失计算模型_使用spark对sparkify的流失预测

spark的流失计算模型Churn prediction, namely predicting clients who might want to turn down the service, is one of the most common business applications of machine learning. It is especially important for those companies providing streaming services. In thi…

区块链开发公司谈区块链与大数据的关系

在过去的两千多年的时间长河中,数字一直指引着我们去探索很多未知的科学世界。到目前为止,随着网络和信息技术的发展,一切与人类活动相关的活动,都直接或者间接的连入了互联网之中,一个全新的数字化的世界展现在我们的…

Jupyter Notebook的15个技巧和窍门,可简化您的编码体验

Jupyter Notebook is a browser bases REPL (read eval print loop) built on IPython and other open-source libraries, it allows us to run interactive python code on the browser.Jupyter Notebook是基于IPL和其他开源库构建的基于REPL(读取评估打印循环)的浏览器&#…

bi数据分析师_BI工程师和数据分析师的5个格式塔原则

bi数据分析师Image by Author图片作者 将美丽融入数据 (Putting the Beauty in Data) Have you ever been ravished by Vizzes on Tableau Public that look like only magic could be in play to display so much data in such a pleasing way?您是否曾经被Tableau Public上的…

BSOJ 2423 -- 【PA2014】Final Zarowki

Description 有n个房间和n盏灯,你需要在每个房间里放入一盏灯。每盏灯都有一定功率,每间房间都需要不少于一定功率的灯泡才可以完全照亮。 你可以去附近的商店换新灯泡,商店里所有正整数功率的灯泡都有售。但由于背包空间有限,你…

WPF绑定资源文件错误(error in binding resource string with a view in wpf)

报错:无法将“***Properties.Resources.***”StaticExtension 值解析为枚举、静态字段或静态属性 解决办法:尝试右键单击在Visual Studio解决方案资源管理器的资源文件,并选择属性选项,然后设置自定义工具属性 PublicResXFile cod…

因果推论第六章

因果推论 (Causal Inference) This is the sixth post on the series we work our way through “Causal Inference In Statistics” a nice Primer co-authored by Judea Pearl himself.这是本系列的第六篇文章,我们将通过Judea Pearl本人与他人合着的《引诱统计学…

如何优化网站加载时间

一、背景 我们要监测网站的加载情况,可以使用 window.performance 来简单的检测。 window.performance 是W3C性能小组引入的新的API,目前IE9以上的浏览器都支持。一个performance对象的完整结构如下图所示: memory字段代表JavaScript对内存的…

熊猫数据集_处理熊猫数据框中的列表值

熊猫数据集Have you ever dealt with a dataset that required you to work with list values? If so, you will understand how painful this can be. If you have not, you better prepare for it.您是否曾经处理过需要使用列表值的数据集? 如果是这样&#xff0…

旋转变换(一)旋转矩阵

1. 简介 计算机图形学中的应用非常广泛的变换是一种称为仿射变换的特殊变换,在仿射变换中的基本变换包括平移、旋转、缩放、剪切这几种。本文以及接下来的几篇文章重点介绍一下关于旋转的变换,包括二维旋转变换、三维旋转变换以及它的一些表达方式&#…

数据预处理 泰坦尼克号_了解泰坦尼克号数据集的数据预处理

数据预处理 泰坦尼克号什么是数据预处理? (What is Data Pre-Processing?) We know from my last blog that data preprocessing is a data mining technique that involves transforming raw data into an understandable format. Real-world data is often incom…

Pytorch中DNN入门思想及实现

DNN全连接层(线性层) 计算公式: y w * x b W和b是参与训练的参数 W的维度决定了隐含层输出的维度,一般称为隐单元个数(hidden size) b是偏差值(本文没考虑) 举例: 输…

IDEA去除mapper.xml文件中的sql语句的背景色

2019独角兽企业重金招聘Python工程师标准>>> IDEA版本 2017.3 mapper.xml文件中的sql语句,总是黄色一大片,看起来不舒服。 按如下设置进行设置即可 此时设置完还有点背景色 再进行一个设置 Ok,完美解决 转载于:https://my.oschina.net/u/3939…

vc6.0 绘制散点图_vc有关散点图的一切

vc6.0 绘制散点图Scatterplots are one of the most popular visualization techniques in the world. Its purposes are recognizing clusters and correlations in ‘pairs’ of variables. There are many variations of scatter plots. We will look at some of them.散点图…

Pytorch中RNN入门思想及实现

RNN循环神经网络 整体思想: 将整个序列划分成多个时间步,将每一个时间步的信息依次输入模型,同时将模型输出的结果传给下一个时间步,也就是说后面的结果受前面输入的影响。 RNN的实现公式: 个人思路: 首…