当前位置:网站首页>Bi skill - judge 0 and null
Bi skill - judge 0 and null
2022-06-25 01:12:00 【Powerbi white tea】
BOSS: Who is that ! White tea , Come here, come here , I have a need to tell you !
White tea :( Black question mark ?) Yo ,BOSS?
BOSS: That's true , We are during the national day , Sold some goods , But some products are special , Part of the sales amount is empty , When we calculate the gross profit, we need to multiply the cost by 1.5; The sales amount of some commodities is 0, The calculation of gross profit is uniformly displayed as 0.01, Can handle no ?
White tea :(????)BOSS, It is possible to , What is the algorithm ?
BOSS: Don't ask too much , Asking is the business of the company !
White tea : Oh , understand !
Under normal circumstances , When we measure data quality , They tend to care about data with numerical values , But in real business , Especially in the financial algorithm ,0 And empty sometimes is also an important calculation basis .
Let's take a look at the case data in this issue :
The data is relatively simple , Only 6 Column , From the screenshot, we can see that the sales amount of some data is 0, Part is empty , But there are costs , Have quantity .
Under normal circumstances, we only need to consider the data that the sales amount is not empty , However, there may be transfer inventory in the actual business 、 Status of complimentary sales .
Therefore, sometimes we prefer to apply financial scenarios , We need to consider this situation , stay PowerBI How to distinguish between 0 And empty cloth ?
We are PowerBI Pass through Filter Function to filter and see .
Code :
Screening 0 =
FILTER ( 'Data', 'Data'[SalesAmt] = 0 )
You can see , Though we pass Filter Function 0 Screening , But the actual result is still empty . Let's continue to filter the null values to see .
Code ;
Filter empty =
FILTER ( 'Data', 'Data'[SalesAmt] = BLANK() )
The same as above , There are still no other changes .
You can think about it , How to solve this problem ?
3
2
1
…
There are two solutions : Strictly equal to ISBLANK.
Strictly equal :
Usually we use the equality operator , In this case, we can use strict equality to distinguish 0 And emptiness .
Code :
Strict screening 0 =
FILTER ( 'Data', 'Data'[SalesAmt] == 0 )
Code :
Strictly filter empty =
FILTER ( 'Data', 'Data'[SalesAmt] == BLANK() )
ISBLANK:
ISBLANK Can identify empty .
Code :
ISBLANK Screening 0 =
FILTER ( 'Data', NOT ISBLANK ( 'Data'[SalesAmt] ) && 'Data'[SalesAmt] = 0 )
Code :
ISBLANK Filter empty =
FILTER ( 'Data', ISBLANK ( 'Data'[SalesAmt] ) )
therefore , We can do this through these two methods BOSS The requirements mentioned at the beginning .
Part of the sales amount is empty , When we calculate the gross profit, we need to multiply the cost by 1.5;
The sales amount of some commodities is 0, The calculation of gross profit is uniformly displayed as 0.01.
gross profit 1:
gross profit 1 =
VAR AMT =
SUM ( 'Data'[SalesAmt] )
VAR COST =
SUMX ( 'Data', [Cost] * [Quantity] )
VAR Result =
SWITCH (
TRUE (),
AMT == BLANK (),
AMT - COST * 1.5,
AMT == 0, 0.01,
AMT - COST
)
RETURN
Result
give the result as follows :
gross profit 2:
gross profit 2 =
VAR AMT =
SUM ( 'Data'[SalesAmt] )
VAR COST =
SUMX ( 'Data', [Cost] * [Quantity] )
VAR Result =
SWITCH ( TRUE (), ISBLANK ( AMT ), AMT - COST * 1.5, AMT = 0, 0.01, AMT - COST )
RETURN
Result
give the result as follows :
friends GET Why? ?
(BOSS: Can you can !)
This is white tea , One PowerBI Beginners .
边栏推荐
- Syntax highlighting of rich text
- bindservice方法实现音乐播放暂停
- Previous basic review (link)
- LLVM TargetPassConfig
- Powerbi - for you who are learning
- The interview questions and answers for the high-frequency software test of Dachang help you prepare for the golden nine silver ten
- EVM简略
- Picture rotation move zoom gradient
- 用手机在同花顺上开户靠谱吗?这样炒股有没有什么安全隐患
- 新手看过来,带你一次性了解“软考”
猜你喜欢
Text editor for QT project practice - Episode 10
4 ans d'expérience de travail, 5 modes de communication Multi - thread ne peuvent pas être décrits, vous osez croire?
108 pages (40000 words) proposal for future apartment intelligent design platform project (version 2022)
Bi-sql top
2022 simulated 100 questions of safety officer-c certificate examination and online simulated examination
4年工作經驗,多線程間的5種通信方式都說不出來,你敢信?
最新QQ微信域名防红PHP程序源码+强制跳转打开
Mobile security tool jar
Using macro code to generate handwriting automatically in word or WPS
生成订单30分钟未支付,则自动取消,该怎么实现?
随机推荐
Transform BeanUtils to achieve list data copy gracefully
I brush the question I - copy the linked list with random pointer
[redis realizes seckill service ②] solution to oversold problem
What to learn in VB [easy to understand]
Which securities company should I choose to open an account online? Is it safe to open an account online?
腾讯搬家了!
Mobile security tool -dex2jar
How about compass stock trading software? Is it safe?
Scala sample object
腾讯完成全面上云 打造国内最大云原生实践
改造一下 BeanUtils,优雅的实现 List 数据拷贝
Previous basic review
Scala sample class
中金财富证券开户佣金多少呢?股票开户交易安全靠谱吗?
丹麦技术大学首创将量子计算应用于能源系统潮流建模
【实用系列】家内wifi全覆盖
Can communication experiment between C and C
使用 Loki 微服务模式部署生产集群
丹麥技術大學首創將量子計算應用於能源系統潮流建模
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?