惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Vulnerabilities – Threatpost
F
Fortinet All Blogs
Vercel News
Vercel News
C
Check Point Blog
P
Privacy International News Feed
Know Your Adversary
Know Your Adversary
Google DeepMind News
Google DeepMind News
T
Troy Hunt's Blog
TaoSecurity Blog
TaoSecurity Blog
I
Intezer
T
The Exploit Database - CXSecurity.com
Security Archives - TechRepublic
Security Archives - TechRepublic
H
Hacker News: Front Page
P
Proofpoint News Feed
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
IT之家
IT之家
D
DataBreaches.Net
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
Y
Y Combinator Blog
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
Lohrmann on Cybersecurity
T
Tenable Blog
大猫的无限游戏
大猫的无限游戏
L
LINUX DO - 最新话题
G
Google Developers Blog
The GitHub Blog
The GitHub Blog
Recorded Future
Recorded Future
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
K
Kaspersky official blog
PCI Perspectives
PCI Perspectives
A
Arctic Wolf
Latest news
Latest news
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
雷峰网
雷峰网
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
P
Palo Alto Networks Blog
The Hacker News
The Hacker News
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
月光博客
月光博客
Schneier on Security
Schneier on Security
M
MIT News - Artificial intelligence

Power BI – Ed_'s Blog

Power BI 由于缺少事实数据,X轴日期不连续 – yywr's Blog Power BI里DAX上下文转换到底是怎么转换的 – yywr's Blog 中国式报表学习解析-多级表头&自定义小计 – yywr's Blog 中国式一页纸矩阵表报告制作解析 – yywr's Blog NPS模型Power BI报表解析记录 – yywr's Blog 数据模型初探 – yywr's Blog PowerBI中DAX语言的上下文是什么 – yywr's Blog
[初接触] DAX 中的行上下文与EARLIER() 函数 – yywr's Blog
yywr · 2018-07-10 · via Power BI – Ed_'s Blog

Skip to content

POWER BI中函数处理的对象的最小单位是列,这意味着,每一次计算都是在这个列中做一次完整的迭代循环计算。

不论是 SUMX() 还是 FILTER() ,给一个参数(列),函数内部都会在这个列中从头到尾,把所有数值计算一遍。

基于这种特性,我们不需要自己在DAX中写迭代代码,因为已经封装到函数内部了。也以此认识到每次用如 SUMX() 计算函数,都至少会有一个迭代循环发生。

EARLIER() 在行上下文中的角色

官方说明:https://msdn.microsoft.com/zh-cn/library/ee634551.aspx

官方的说明向来拗口,以下列案例说明,计算比自身 Cost 大的 Cost 的合计

这里用了两个函数,一个SUMX(), 一个是 FILTER(), 两个内部都有迭代循环,而且在这个例子中是迭代同一列。

在一般的编程语言中很好理解,就是一个循环嵌套,在DAX变得更加抽象了,这个例子如果用其它编程语言来写话,类似于下面这样:

同一组数据,被嵌套迭代了两次,由于DAX函数每次都是处理一列,不像其它编程语言以数组下标或指针的方式访问一个个具体的元素值。而是统一以  ‘[] 的方式表示,具体的元素值在函数内部处理。

这个表达式中,蓝色框中的 ‘表'[列] (’Sheet1′[Cost])表示第一次迭代循环中的当前行值,红色框中表示第二次迭代循环中的当前行值。

第二次迭代循环中的当前行值要与第一次迭代中的当前行值计算,肯定不是’Sheet1′[Cost]和’Sheet1′[Cost]比较。这里用了 EARLIER() 来传递外层迭代循环中的当前行值,让它参与到内层循环的计算中

讨巧一点方法就是用一个变量来存储外层迭代循环中的当前行值,这样比使用 EARLIER() 更好理解一点

关于行上下文的理解,可以看看这篇:PowerBI中DAX语言的上下文是什么