简体   繁体   English

基于行值的Powerpivot DAX总和

[英]Powerpivot DAX sum based on row value

I am trying to create a running total based on 4 criteria but can't seem to get it to work - sorry very new to both powerpivot and DAX. 我正在尝试根据4个条件创建运行总计,但似乎无法使其正常工作-对powerpivot和DAX来说都是很新的。

I have a Query that has a total of 17 columns - 13 actual data and 4 calculated. 我有一个查询,共有17列-13实际数据和4计算。

I want to get a cumulative total based on 4 criteria. 我想根据4个条件得出累计总数。 I haven't even been able to get 1 criteria working so far: 到目前为止,我什至无法获得1条标准:

CALCULATE(
    SUM(Tonnes),
    Filter(Query,[Deliveryid]=[Deliveryid])
    )

Basically want to sum all the tonnes for each deliveryid - this is simple in a pivot, but i want to eventually do this for all dates before the date value in the row and for each commodity and delivery address etc. 基本上是想对每个deliveryid的所有吨加总-这在枢轴中很简单,但我最终希望针对行中日期值之前的所有日期以及每种商品和交货地址等进行最终汇总。

Any help would be appreciated. 任何帮助,将不胜感激。

Regarding your specific requirement to sum all the tonnes for each Deliveryid, you're close. 关于将每个Deliveryid的所有吨加总的具体要求,您很接近。 Try this: =CALCULATE(SUMX(Table1,[Tonnes]),FILTER(Table1,[Deliveryid]=EARLIER([Deliveryid]))) . 试试这个: =CALCULATE(SUMX(Table1,[Tonnes]),FILTER(Table1,[Deliveryid]=EARLIER([Deliveryid]))) It will sum the Tonnes for each Deliveryid. 它将汇总每个Deliveryid的吨数。

Regarding your follow-on desire to sum all the tonnes for each Deliveryid for the dates preceding the current date, try this: =CALCULATE(SUMX(Table1,[Tonnes]),FILTER(FILTER(Table1,[Deliveryid]=EARLIER([Deliveryid])),[Date]<EARLIER([Date]))) . 关于您希望对当前日期之前的日期的每个Deliveryid汇总所有吨的后续愿望,请尝试以下操作: =CALCULATE(SUMX(Table1,[Tonnes]),FILTER(FILTER(Table1,[Deliveryid]=EARLIER([Deliveryid])),[Date]<EARLIER([Date])))

The table below might help show what these do (I used very long column titles to hopefully make this more understandable): 下表可能有助于说明这些操作(我使用了很长的列标题,希望可以使它更容易理解):

TotalTonnesForDeliveryid (made with the first code item above) simply totals tonnes by Deliveryid. TotalTonnesForDeliveryid(由上面的第一个代码项制成)仅按Deliveryid总计吨。 In the table below, you see the TotalTonnesForDeliveryid for Deliveryid 1 is 91 tonnes ... 38 (from 1/1/2017) + 23 (from 1/3/2017) + 30 (from 1/6/2017). 在下表中,您看到Deliveryid 1的TotalTonnesForDeliveryid为91吨... 38(从1/1/2017起)+ 23(从1/3/2017起)+ 30(从1/6/2017起)。

TotalTonnesForDeliveryBeforeCurrentDate (made with the second code item above) totals tonnes by Deliveryid only for the dates preceding the current date . TotalTonnesForDeliveryBeforeCurrentDate(由上面的第二个代码项制成) 按Deliveryid汇总了当前日期之前的日期的吨数。 The reason TotalTonnesForDeliveryBeforeCurrentDate shows blanks for first occurences of Deliveryid is because there was no prior delivery. TotalTonnesForDeliveryBeforeCurrentDate在首次出现Deliveryid时显示空白的原因是因为没有先前的交货。 If more than one delivery has been made for a particular Deliveryid, each following occurence of the Deliveryid shows an accumulation of the previous dates' tonnes. 如果为一个特定的Deliveryid进行了多次交货,则每次出现的Deliveryid都会显示以前日期的吨数。 So for Deliveryid 1: the initial delivery date (1/1/2017) shows blank TotalTonnesForDeliveryidBeforeCurrentDate (because there was no previous delivery); 因此,对于Deliveryid 1:初始交付日期(2017年1月1日)显示空白TotalTonnesForDeliveryidBeforeCurrentDate(因为之前没有交付); the second delivery date (1/3/2017) shows 38 tonnes (which is what was delivered on 1/1/2017); 第二个交货日期(1/3/2017)显示为38吨(2017年1月1日交货); and the third delivery date (1/6/2017) shows 61 tonnes (which is the 38 from the first delivery + the 23 from the second delivery). 第三次交货日期(2017年1月6日)显示为61吨(第一次交付38吨,第二次交付23吨)。

在此处输入图片说明

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

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