当前位置:网站首页>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 .
边栏推荐
- QT electronic clock
- Go语言运算符(第8课下)
- 2022年危险化学品经营单位安全管理人员考试试题及模拟考试
- 108页(4万字)未来公寓智能化设计平台项目方案建议书2022版
- adb shell sendevent
- Super detailed description and derivation of convolution and deconvolution (deconvolution is also called transpose convolution and fractional step convolution)
- Deploy a production cluster using Loki microservice pattern
- ImageView展示网络图片
- 4 years of working experience, and you can't tell the five communication modes between multithreads. Can you believe it?
- Première application de l'informatique quantique à la modélisation des flux de puissance dans les systèmes énergétiques à l'Université technique danoise
猜你喜欢

51单片机多机通信

Syntax highlighting of rich text

丹麦技术大学首创将量子计算应用于能源系统潮流建模

The interview questions and answers for the high-frequency software test of Dachang help you prepare for the golden nine silver ten

JS Chapter 1 Summary

2022安全员-C证考试模拟100题及在线模拟考试

The basic principle and application of iterator and enhanced for

Deploy a production cluster using Loki microservice pattern

QT(35)-操作EXCEL-QXlsx-QAxObject
The latest QQ wechat domain name anti red PHP program source code + forced jump to open
随机推荐
Deploy a production cluster using Loki microservice pattern
Go language operators (under Lesson 8)
QT(36)-rapidjson解析嵌套的json
图书馆管理系统代码源码(php+css+js+mysql) 完整的代码源码
[redis realizes seckill business ③] specific implementation of optimistic lock for oversold problem
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
The latest QQ wechat domain name anti red PHP program source code + forced jump to open
戴尔为何一直拒绝将商用本的超薄推向极致?
图片旋转移动缩放渐变
Transform BeanUtils to achieve list data copy gracefully
Syntax highlighting of rich text
Which securities company should I choose to open an account online? Is it safe to open an account online?
15.线程同步的几种方法
Scala IO read by character
[practical series] full WiFi coverage at home
Simulation questions and answers of the latest national fire facility operator (senior fire facility operator) in 2022
[redis realizes seckill service ④] one order for one person, and cannot be purchased repeatedly
Welcome to the new world of Lenovo smart screen
Is it reliable to open an account on the flush with a mobile phone? Is there any hidden danger in this way
adb shell sendevent