如何解决PowerBI 和 MAX 用于乘以值? 日志1log2
log1
date cost
15-May 10
18-May 15
17-May 12
log2
date cost
15-May 1
16-May 3
18-May 2
我想要做的是通过根据 log1 中的日期(5 月 18 日和 15 美元)查找最新成本值并将其乘以 log2 中的最新成本(5 月 18 日和 2 )。然后,我想将该度量值放入带有日期的简单条形图中,在本例中为 5 月 18 日和 30 美元。
我玩过 MAX,但似乎无法弄清楚这一点。帮助?
谢谢!
我认为这类似于 Multiply columns based on the Year and Month 但不确定。
解决方法
你需要什么样的输出?
Measure =
var maxLog1 = CALCULATE( MAX(Log1[date]),REMOVEFILTERS(Log1[date]))
var maxlog2 = CALCULATE( MAX(log2[date]),REMOVEFILTERS(Log2[date]))
var result = CALCULATE( MAX(Log1[cost]),Log1[date] = maxLog1) * CALCULATE(MAX(log2[cost]),log2[date] = maxlog2)
return
result
,
如果你的表格真的那么简单,你可以使用名为 lookupvalue 的 dax 函数 它类似于excel中的vlookup,您可以根据日期查找成本
所以在这个例子中它会被添加到 log2 表中
Amount = 'log2'[cost] * LOOKUPVALUE('log1'[cost],'log1'[date],'log2'[date])
https://docs.microsoft.com/en-us/dax/lookupvalue-function-dax
如果日期列之间存在关系,您就可以使用 Related() 函数
,这是一个替代解决方案,假设如下:
- 每个日志表中每天都有一个唯一的
# generate some random x and y values x = as.POSIXlt("2017-02-03 08:00:00") + 100*rnorm(50,60*60) y = cos(as.numeric(x)/(3600*25))+rnorm(length(x),0.3) # making plots with different time steps par(mfrow=c(3,1)) plot(x,y,xaxt='n',main='2 Days Ticks') axis(side=1,at=seq(as.POSIXlt("2017-01-27 00:00:00"),as.POSIXlt("2017-02-9 23:59:59"),by=48*3600),labels = seq(as.POSIXlt("2017-01-27 00:00:00"),by=48*3600) ) plot(x,main='1 Day Ticks') axis(side=1,by=24*3600),by=24*3600) ) plot(x,main='12-Hour Ticks') axis(side=1,by=12*3600),by=12*3600) )
- 没有空的缺失日期,尽管它不会破坏计算。
-
cost
表存储日期。
数据模型
日历表:计算
Calendar
计算:测量
此计算取决于将 Calendar =
CALENDAR (
MIN ( MIN ( log1[date] ),MIN ( log2[date] ) ),MAX ( MAX ( log1[date] ),MAX ( log2[date] ) )
)
用作视觉效果中的中心 Calendar[Date]
值。
Date
输出 1
或者,如果您想创建一个独立于将日期作为视觉一部分的计算并检索正确的总数。
Cost = sum(log1[cost])*sum(log2[cost])
这意味着您需要将关系更改为 1:1 和 CostSumx =
sumx('Calendar',RELATED('log1'[cost])*RELATED(log2[cost]))
输出 2
表格
日志1
日期 | 成本 |
---|---|
2021 年 5 月 15 日 | 20 |
2021 年 5 月 16 日 | 30 |
2021 年 5 月 17 日 | 40 |
log2
日期 | 成本 |
---|---|
2021 年 5 月 15 日 | 1 |
2021 年 5 月 16 日 | 2 |
2021 年 5 月 17 日 | 3 |
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。