当前位置:网站首页>Bi skills - permission axis
Bi skills - permission axis
2022-07-04 19:20:00 【Powerbi white tea】

BOSS:( Pull a long face ) What about white tea ?
colleagues :( Push... Push ) Wake up , White tea ,BOSS Call you !
White tea :( A face of meng ) Yo , Boss ?
BOSS:( A look of disdain ) White tea , There is a need. , Users need to be in the same chart , Indicators can be switched .
White tea : This has been done before , It's a dynamic indicator !
BOSS: Don't worry. , also , It's our different users , The roles are different , Whether different users can come in and see the coordinate axis of the chart varies from person to person ?
White tea : Permission axis ?
BOSS: Yes !
White tea :OK, Can do !
BI Report in practical application , Report permissions often need to be configured , for example RLS jurisdiction 、OLS jurisdiction 、 Page permissions, etc .
Actually , In addition to these three permissions , There is also a special permission requirement .
a sheet BI report form , There are many users , Different user roles are different . A lot of times , When users expect to open the report , According to your role , See the dimensions you need to observe .
So in PowerBI in , How to realize such requirements ?

Let's take a look at the case data in this issue :





There are five tables of case data .Date Date sheet ,Product Product list ,Store Store table ,Access Permissions on the table ,Sales Sales fact sheet .
from Access You can see in the permission table , We have three users , On behalf of the person in charge of the branch 、 Product owner 、 Market leader , We need to , According to different roles of users , Automatically fit the corresponding dimension coordinate axis .
Import data into PowerBI, The model relationship is shown in the figure below :

Attention, boys ,Access This table , There is no need to establish model relationships with other tables .
Build the metrics of the foundation :
sales volumes :
A. sales volumes =
SUM ( Fact_Sales[Quantity] )
Sales amount :
B. Sales amount =
SUMX ( 'Fact_Sales', [Quantity] * RELATED ( Dim_Product[Price] ) )
Build a dimension table for indicator switching :

Add dynamic switching metrics :
C.KPI =
IF ( SELECTEDVALUE ( Dim_KPI[Sort] ) = 1, [A. sales volumes ], [B. Sales amount ] )
Come here , Our preparations are over , Think about it , How to achieve the dynamic switching effect of permission axis in the next step .
Think about it
1
2
3
…
The permission dynamic axis needs to complete two conditions :
1. There needs to be a table containing all user demand dimensions ;
2. You need to configure the data permissions of dimension tables according to user permissions .
Build a dynamic analysis dimension table :
Create a new table , Enter the following code :
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 )
give the result as follows :

This code , Equivalent to store 、 product 、 These three dimensions of the city are forcibly combined to generate a new table .
Add the following measures :
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 ()
)
The effect is as follows :

White tea hopes that the title can also be automatically adapted according to the user's permission .
Add the following code :
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
Add user permission metrics :
The measurements are as follows :
F.Access =
VAR UserAccess =
CALCULATETABLE (
VALUES ( Dim_Access[ Line authority ] ),
'Dim_Access'[ mailbox ] = USERPRINCIPALNAME ()
)
VAR Access =
SELECTEDVALUE ( Dim_Analysis[Analysis] ) IN UserAccess
RETURN
Access
Under the modeling panel , Select the management role , Enter character “Access”, Enter the following code :
[F.Access]=True()
give the result as follows :

Beautify the report , The final display effect is shown in the figure below :



(BOSS:Nice!)
Demo Documents on the planet of knowledge .
This is white tea , One PowerBI Beginners .
边栏推荐
- 6.26CF模拟赛E:价格最大化题解
- Esp32-c3 introductory tutorial questions ⑫ - undefined reference to ROM_ temp_ to_ power, in function phy_ get_ romfunc_ addr
- Scala basic tutorial -- 19 -- actor
- Process of manually encrypt the mass-producing firmware and programming ESP devices
- Scala basic tutorial -- 18 -- set (2)
- Unity编辑器扩展C#遍历文件夹以及子目录下的所有图片
- 启牛开的证券账户安全吗?
- 基于unity的愤怒的小鸟设计
- Scala basic tutorial -- 15 -- recursion
- 2021 合肥市信息学竞赛小学组
猜你喜欢

激进技术派 vs 项目保守派的微服务架构之争

字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验

Microservice architecture debate between radical technologists vs Project conservatives
redis分布式锁的8大坑总结梳理

Nebula importer data import practice

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

Nebula Importer 数据导入实践

NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读

Scala basic tutorial -- 20 -- akka
![[uniapp] uniapp development app online Preview PDF file](/img/11/d640338c626249057f7ad616b55c4f.png)
[uniapp] uniapp development app online Preview PDF file
随机推荐
php伪原创api对接方法
Rookie post station management system based on C language
基于C语言的菜鸟驿站管理系统
6.26cf simulation race e: solution to the problem of price maximization
利用策略模式优化if代码【策略模式】
Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
From automation to digital twins, what can Tupo do?
【机器学习的数学基础】(一)线性代数(Linear Algebra)(上+)
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
Interpretation of SIGMOD '22 hiengine paper
1、 Introduction to C language
神经网络物联网是什么意思通俗的解释
启牛开的证券账户安全吗?
【2022年江西省研究生数学建模】水汽过饱和的核化除霾 思路分析及代码实现
Pb extended DLL development (super chapter) (VII)
Scala basic tutorial -- 14 -- implicit conversion
Halcon template matching
Wanghongru research group of Institute of genomics, Chinese Academy of Agricultural Sciences is cordially invited to join
整理混乱的头文件,我用include what you use
IBM WebSphere MQ检索邮件