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,一经查实,立即删除!

相关文章

字符串匹配 sunday算法

#include"iostream" #include"string.h" using namespace std;//BF算法 int strfind(char *s1,char *s2,int pos){int len1 strlen(s1);int len2 strlen(s2);int i pos - 1,j 0;while(j < len2){if(s1[i j] s2[j]){j;}else{i;j 0;}}if(j len2){…

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

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

Adobe After Effects CS6 操作记录

安装 After Effects CS6 在Mac OS 10.12.5 上无法直接安装, 需要浏览到安装的执行文件后才能进行 https://helpx.adobe.com/creative-cloud/kb/install-creative-suite-mac-os-sierra.html , 但是即使安装成功, 也不能正常启动, 会报"You can’t use this version of the …

数据库逻辑删除的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…

好用的模块

import requests# 1、发get请求urlhttp://api.xxx.xx/api/user/sxx_infodata{stu_name:xxx}reqrequests.get(url,paramsdata) #发get请求print(req.json()) #字典print(req.text) #string,json串# 返回的都是什么# 返回的类型是什么# 中文的好使吗# 2、发请求posturlhttp://api…

5940. 从数组中移除最大值和最小值

5940. 从数组中移除最大值和最小值 给你一个下标从 0 开始的数组 nums &#xff0c;数组由若干 互不相同 的整数组成。 nums 中有一个值最小的元素和一个值最大的元素。分别称为 最小值 和 最大值 。你的目标是从数组中移除这两个元素。 一次 删除 操作定义为从数组的 前面 …

BZOJ4127Abs——树链剖分+线段树

题目描述 给定一棵树,设计数据结构支持以下操作 1 u v d  表示将路径 (u,v) 加d 2 u v 表示询问路径 (u,v) 上点权绝对值的和 输入 第一行两个整数n和m&#xff0c;表示结点个数和操作数接下来一行n个整数a_i,表示点i的权值接下来n-1行,每行两个整数u,v表示存在一条(u,v)的…

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

数据挖掘流程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…

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

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

786. 第 K 个最小的素数分数

786. 第 K 个最小的素数分数 给你一个按递增顺序排序的数组 arr 和一个整数 k 。数组 arr 由 1 和若干 素数 组成&#xff0c;且其中所有整数互不相同。 对于每对满足 0 < i < j < arr.length 的 i 和 j &#xff0c;可以得到分数 arr[i] / arr[j] 。 那么第 k 个…

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

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

域嵌套太深_pyspark如何修改嵌套结构域

域嵌套太深In our adventures trying to build a data lake, we are using dynamically generated spark cluster to ingest some data from MongoDB, our production database, to BigQuery. In order to do that, we use PySpark data frames and since mongo doesn’t have …

redis小结

Redis 切换到redis的目录 启动&#xff1a;./redis-server 关闭&#xff1a;killall redis-server Redis的数据类型&#xff1a; String字符 list链表 set集合&#xff08;无序&#xff09; Sort Set排序&#xff08;有序&#xff09; hash数据类型 string类型的数据操作 re…

WIN10下ADB工具包安装的教程和总结 --201809

ADB&#xff08;Android Debug Bridge&#xff09;是Android SDK中的一个工具, 使用ADB可以直接操作管理Android模拟器或者真实的Andriod设备。 ADB主要功能有: 在Android设备上运行Shell(命令行)管理模拟器或设备的端口映射在计算机和设备之间上传/下载文件将电脑上的本地APK软…

1816. 截断句子

1816. 截断句子 句子 是一个单词列表&#xff0c;列表中的单词之间用单个空格隔开&#xff0c;且不存在前导或尾随空格。每个单词仅由大小写英文字母组成&#xff08;不含标点符号&#xff09;。 例如&#xff0c;“Hello World”、“HELLO” 和 “hello world hello world”…

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…

峰识别 峰面积计算 peak detection peak area 源代码 下载

原文:峰识别 峰面积计算 peak detection peak area 源代码 下载Comparative analysis of peak-detection techniques for comprehensive two-dimensional chromatography http://www.docin.com/p-172045359.html http://terpconnect.umd.edu/~toh/spectrum/ipeak.html R…

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

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

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(读取评估打印循环)的浏览器&#…

给定有权无向图的邻接矩阵如下,求其最小生成树的总权重,代码。

#include<bits/stdc.h> using namespace std; #define INF 0x3f3f3f3f const int maxn 117; int m[maxn][maxn]; int vis[maxn], low[maxn]; /* 对于这道题目来将&#xff0c;m就是临接矩阵&#xff0c;vis是访问标记数组&#xff0c;low是最短距离数组 */ int n; int …