简体   繁体   English

基于最后一列值和过滤器的Power BI度量

[英]Power BI measure based on last column value and filter

I have a table with records of some people's weights: 我有一张桌子,上面记录着一些人的体重:

Year    Person  Weight
2010    Mike    75
2010    Laura   60
2011    Mike    80
2011    Laura   55
2012    Laura   58

I want to create a Measure to find out the average weight based on the last weight of each person : 我想创建一个度量根据每个人的最后体重找到平均体重

  • Report Year = no filter => Mike = 80, Laura = 58, Average = 69 报告年份=没有过滤器=>迈克= 80,劳拉= 58, 平均值= 69
  • Report Year = 2011 => Mike = 80, Laura = 55, Average = 67.5 报告年度= 2011 =>迈克= 80,劳拉= 55, 平均值= 67.5
  • Report Year = 2010 => Mike = 75, Laura = 60, Average = 67.5 报告年份= 2010 =>迈克= 75,劳拉= 60, 平均值= 67.5

bearing in mind that the weight can go up/down over time, so functions like MAXX or MINX won't help. 请注意,重量会随着时间的推移而上升/下降,因此MAXXMINX类的功能将无济于事。 The most logical I could find was this: 我能找到的最合逻辑的是:

lastWeight = LASTNONBLANK(Weights[Weight],FILTER(Weights,Weights[Person]=Weights[Person]))

But it's complaining that it returns multiple columns. 但它抱怨它返回多个列。 It seems simple but I'm just completely stuck. 看起来很简单,但我完全被卡住了。

Any idea how I can create the measure to have the last weight value for each person? 知道如何创建每个人的最后体重值的量度吗?

Many thanks. 非常感谢。

PS: initially I thought a column would be a good idea, but it's not, as I want to see the last weight for a given period of time, so it will be a measure calculated on the fly based on my report time range PS:最初我认为专栏文章是个好主意,但事实并非如此,因为我想查看给定时间段内的最后权重,因此这将是根据我的报告时间范围即时计算的度量

This is the data that I used :- 这是我使用的数据:

Year    Person  Weight
2010    Mike    75
2010    Laura   60
2011    Mike    80
2011    Laura   55
2012    Laura   58
2010    Mike    50
2010    Laura   51
2011    Mike    52
2011    Laura   53
2012    Laura   54
2010    Mike    99
2010    Laura   100
2011    Mike    101
2011    Laura   102
2012    Laura   103

I first created an Index column by going into edit queries 我首先通过进入编辑查询来创建索引列

索引栏创建

So, once I created the Index Column - I then created a measure called as 因此,一旦创建了索引列-然后创建了一个称为

Last Weight in the Data = LASTNONBLANK(Table2[Weight],MAX(Table2[Index]))

So now, I can use this measure on my visuals :- 所以现在,我可以在视觉效果上使用此度量了:

For example:- 例如:-

最后重量测量

Let me know, if this doesn't help. 让我知道,如果这样做没有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM