Forum Discussion
Remove Duplicates?
Hey,
sure.
At the heart of this meausre there are two nested SUMX('table', expression)
SUMX('table'
,SUMX('table',IF(...)
)SUMX() is an table iterator function this means, that the expression is evaluated for each row of the table. The first table calculated by using the VALUES() function, VALUES always returns a one column sized table, this table is calculated by the column with all the IDs (the orders). Two things to know about this function is the fact , that it returns the unique values of the used column and the values returns the values in the current FILTERCONTEXT.
Implicity the value is implicitly used as filter for the the calculation of the expression.
The expression for the 1st SUMX is also a SUMX. Before the second expression is evaluated the MAX date is stored in the variable lastorderdate. This happens for each pass of the first iteration.
The 2nd table (1st parameter of the 2nd SUMX) is the table and is implicitly filtered by each ID. The 2nd expression checks if the date equals the value of the variable, if this is the case, the value "RemainingPayment" is used, otherwise the IF statement returns BLANK.
It is necessary to use SUMX for the calculation of the TOTAL row, where no ID is determining the FILTERCONTEXT.
I hope this explanation makes things a little clearer.
The function does not consider if there are more than 1 row with exactly the same lastorderdate (date and time), if this would be the case a rule has to be defined that describes which row has to be considered and the measure has to be adjusted accordingly.
Regards
thanks for your explanation. It's great that you mentioned the condition at the last. As my data have more than 1 row with exactly same date. Hence do you have any idea to do that?
Regards,
Chung.
- TomMartens9 years agoSuper User
Hey,
I guess the row to use would be, the row with the MIN('table'[RemainingPayment].
So, without trying I would define a 2nd variable
minRemainingPayment = CALCULATE( MIN('table'[RemainingPayment]) )and adjust the IF statement like so
IF('OrdersPayment'[Date] = latestOrderDate && 'OrdersPayment'[RemainingPayment] = minRemainigPaymentHope this helps
Regards
- TomMartens9 years agoSuper User
Hey,
without knowing yor business rules it's just guesswork, but the constraint "more than one row" has to be considered no matter what date is used.
Blank "Remaining Payment" rows are due to the "Goods in transit" concept, from my point of view these goods to not affect the remainig payment, but maybe you have another kpi that exactly describes the difference between "goods send" and "goods received".
Regards
- TomMartens9 years agoSuper User
Hey,
and as I was staring on the measure I would rewrite the measure for performance reason like so
Remaining Payment latestOrder optimized = SUMX( VALUES('OrdersPayment'[ID]) , var latestOrderDate = CALCULATE(MAX('OrdersPayment'[Date])) var minRemainigPayment = CALCULATE(MIN('OrdersPayment'[RemainingPayment])) return CALCULATE( SUM('OrdersPayment'[RemainingPayment]) ,'OrdersPayment'[Date] = latestOrderDate ,'OrdersPayment'[RemainingPayment] = minRemainigPayment ) )Regards
- CTan429 years agoHelper II
I would like to explain what am i doing at the moment (the business rules). The data is from a normal food shops. Basically the idea is to find out how many (orders) and how much (values) of goods are yet to be received. As the goods are yet to be received, the payment won't be made until the goods are received. For the orders part, it is easy to calculate. I can just use 'distinctcount' function for the ID as every goods has a unique ID. For the payment part, it was the hardest part. I need to calculate how much payment for those goods (yet to be received). Wish you could understand what am i doing atm. :) really appreaciate ur help.
Regards.
- TomMartens9 years agoSuper User
Hey, thanks for the explanation.
Can you provide sample datarow that depicts goods in transit, not yet received by a store and not yet payed. Does your table also distinguishes between orderdate, shipdate and receiveddate, also for the figures quantity and payment.
Regards