当前位置:网站首页>BI技巧丨权限轴
BI技巧丨权限轴
2022-07-04 17:40:00 【PowerBI丨白茶】

BOSS:(愁眉苦脸)白茶呢?
同事:(推一推)醒醒,白茶,BOSS喊你!
白茶:(一脸懵)咋了,老板?
BOSS:(一脸嫌弃)白茶,有个需求,用户要求在同一个图表中,指标可以切换。
白茶:这个之前做过啊,就是动态指标啊!
BOSS:别急,还有,就是我们不同的用户,角色是不一样的,能不能让不同用户进来看到图表的坐标轴因人而异?
白茶:权限轴?
BOSS:是的!
白茶:OK,能搞!
BI报表在实际应用中,往往需要对报表权限进行配置,例如RLS权限、OLS权限、页面权限等等。
其实,除了这三种权限之外,还有一种特殊的权限需求。
一张BI报表,面对的用户有很多,而不同的用户角色是不一样的。很多时候,用户期望打开报表时,可以根据自己的角色,看到自己需要观测的维度。
那么在PowerBI中,如何去实现这样的需求呢?

先来看看本期的案例数据:





案例数据共计五张表。Date日期表,Product产品表,Store门店表,Access权限表,Sales销售事实表。
从Access权限表中可以看到,我们一共有三个用户,分别代表分店负责人、产品负责人、市场负责人,我们需要做到,根据用户的不同角色,自动适配对应的维度坐标轴。
将数据导入到PowerBI,模型关系如下图:

小伙伴们注意,Access这张表,不需要和其他表建立模型关系。
构建基础的度量值:
销售数量:
A.销售数量 =
SUM ( Fact_Sales[Quantity] )
销售金额:
B.销售金额 =
SUMX ( 'Fact_Sales', [Quantity] * RELATED ( Dim_Product[Price] ) )
构建指标切换的维度表:

添加动态切换度量值:
C.KPI =
IF ( SELECTEDVALUE ( Dim_KPI[Sort] ) = 1, [A.销售数量], [B.销售金额] )
到这里,我们的准备工作就结束了,思考一下,下一步要如何达成权限轴的动态切换效果。
思考一下
1
2
3
…
权限动态轴需要完成两个条件:
1.需要有一张包含所有用户需求维度的表;
2.需要根据用户权限配置维度表的数据权限。
构建动态分析维度表:
新建一张表,输入如下代码:
Dim_Analysis =
VAR Store =
SELECTCOLUMNS (
ADDCOLUMNS ( DISTINCT ( 'Dim_Store'[StoreName] ), "Analysis", "1" ),
"Analysis", [Analysis],
"Display", [StoreName]
)
VAR ProductName =
SELECTCOLUMNS (
ADDCOLUMNS ( DISTINCT ( 'Dim_Product'[ProductName] ), "Analysis", "2" ),
"Analysis", [Analysis],
"Display", [ProductName]
)
VAR City =
SELECTCOLUMNS (
ADDCOLUMNS ( DISTINCT ( 'Dim_Store'[City] ), "Analysis", "3" ),
"Analysis", [Analysis],
"Display", [City]
)
RETURN
UNION ( Store, ProductName, City )
结果如下:

这段代码,相当于把门店、产品、城市这三个维度强行组合生成一张新的表。
添加如下度量值:
D.AnalysisKPI =
VAR Store =
TREATAS ( VALUES ( 'Dim_Analysis'[Display] ), 'Dim_Store'[StoreName] )
VAR ProductName =
TREATAS ( VALUES ( 'Dim_Analysis'[Display] ), 'Dim_Product'[ProductName] )
VAR City =
TREATAS ( VALUES ( 'Dim_Analysis'[Display] ), 'Dim_Store'[City] )
VAR Analysis =
SELECTEDVALUE ( 'Dim_Analysis'[Analysis] )
RETURN
SWITCH (
TRUE (),
Analysis = "1", CALCULATE ( [C.KPI], Store ),
Analysis = "2", CALCULATE ( [C.KPI], ProductName ),
Analysis = "3", CALCULATE ( [C.KPI], City ),
BLANK ()
)
效果如下:

白茶希望标题也可以根据用户的权限进行自动适配。
添加如下代码:
E.Title =
VAR T1 =
IF ( SELECTEDVALUE ( Dim_KPI[Sort] ) = 1, "Sales Volume", "Revenue" )
VAR T2 =
SELECTEDVALUE ( Dim_Analysis[Analysis] )
VAR T3 =
SWITCH (
TRUE (),
T2 = "1", "Store",
T2 = "2", "Product",
T2 = "3", "City",
"BaiCha"
)
RETURN
T1 & " Analysis By " & T3
添加用户权限度量值:
度量值如下:
F.Access =
VAR UserAccess =
CALCULATETABLE (
VALUES ( Dim_Access[行权限] ),
'Dim_Access'[邮箱] = USERPRINCIPALNAME ()
)
VAR Access =
SELECTEDVALUE ( Dim_Analysis[Analysis] ) IN UserAccess
RETURN
Access
在建模面板下,选择管理角色,输入角色“Access”,输入如下代码:
[F.Access]=True()
结果如下:

美化一下报表,最终展示的效果如下图:



(BOSS:Nice!)
Demo文件在知识星球。
这里是白茶,一个PowerBI的初学者。
边栏推荐
- 工厂从自动化到数字孪生,图扑能干什么?
- One question per day (2022-07-02) - Minimum refueling times
- Pb extended DLL development (super chapter) (VII)
- Learning path PHP -- phpstudy "hosts file does not exist or is blocked from opening" when creating the project
- 2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import 'fmt' func
- Scala basic tutorial -- 20 -- akka
- Li Kou brush question diary /day5/2022.6.27
- How is the entered query SQL statement executed?
- Digital "new" operation and maintenance of energy industry
- Scala基础教程--17--集合
猜你喜欢

Scala基础教程--15--递归

Scala basic tutorial -- 13 -- advanced function

Scala基础教程--18--集合(二)

整理混乱的头文件,我用include what you use

Mxnet implementation of googlenet (parallel connection network)
![[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation](/img/63/8d5f875b4409511628faf2914836d3.png)
[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation

神经网络物联网应用技术学什么

正则替换【JS,正则表达式】
![[mathematical modeling of graduate students in Jiangxi Province in 2022] analysis and code implementation of haze removal by nucleation of water vapor supersaturation](/img/da/d46cca19f34223d29003be2e33aaa4.png)
[mathematical modeling of graduate students in Jiangxi Province in 2022] analysis and code implementation of haze removal by nucleation of water vapor supersaturation

【2022年江西省研究生数学建模】水汽过饱和的核化除霾 思路分析及代码实现
随机推荐
Is the securities account opened by qiniu safe?
Torchdrug tutorial
Deleting nodes in binary search tree
From automation to digital twins, what can Tupo do?
Angry bird design based on unity
[go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
神经网络物联网应用技术学什么
Using FTP
How is the entered query SQL statement executed?
一、C语言入门基础
One question per day (2022-07-02) - Minimum refueling times
How to modify icons in VBS or VBE
力扣刷题日记/day3/2022.6.25
ESP32-C3入门教程 问题篇⑫——undefined reference to rom_temp_to_power, in function phy_get_romfunc_addr
Li Kou brush question diary /day8/7.1
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
[cloud voice suggestion collection] cloud store renewal and upgrading: provide effective suggestions, win a large number of code beans, Huawei AI speaker 2!
File processing examples of fopen, FREAD, fwrite, fseek
建立自己的网站(15)
6.26CF模拟赛E:价格最大化题解