Forum Discussion
Join with Clauses
- 4 years ago
Hi Diogo_Dalla ,
Please try the following measure or custom column(PQ).
Measure:
SumCost = SUMX ( SUMMARIZE ( Scrap, Scrap[Order], "_sum", CALCULATE ( SUM ( 'Order'[Cost] ), FILTER ( 'Order', 'Order'[Step] <= MAX ( Scrap[Step] ) && 'Order'[Order] = MAX ( 'Scrap'[Order] ) ) ) ), [_sum] )PQ Column:
JoinOrderCost = let myfunction = (CurrentOrder, CurrentStep) => let SelectRows = Table.SelectRows(Order, each [Order] = CurrentOrder and [Step] <= CurrentStep) in SelectRows, Data = List.Sum( myfunction([Order],[Step])[Cost]) in DataIf the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Diogo_Dalla ,
Please try the following measure:
Cost =
CALCULATE (
SUM ( 'Order'[Cost] ),
FILTER ( 'Order', 'Order'[Step] <= MAX ( Scrap[Step] ) )
)
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Diogo_Dalla4 years agoFrequent Visitor
Hi,
THank you for your reply.
I checked the model that you sent, but I didn't find where you have added the DAX Code.
Have you merged the two tables?
Thank you,
Diogo Dalla
- v-kkf-msft4 years agoCommunity Support
Hi Diogo_Dalla ,
I did not merge the two tables, I simply created a measure as shown below.
Or try to create a custom column in Power Query to get the data from the Order table and extend it.
= Table.SelectRows(Order, each ([Step] <= #"Changed Type"{0}[Step]))If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- Diogo_Dalla4 years agoFrequent Visitor
Hi,
I think that it is almost there.
Doing the models that you shared I found the following:
* Model1 - The DAX code below is not filtering by Order.
FILTER ( 'Order', 'Order'[Step] <= MAX ( Scrap[Step] ) )I added the following code
Cost = CALCULATE ( SUM ( 'Order'[Cost] ), FILTER ( 'Order', 'Order'[Step] <= MAX ( Scrap[Step] ) && 'order'[order] = Max(Scrap[order]) ) )But it will bring the Max Scrap.Step and the Max Scrap.order
I was able to do it in Excel with power query this way:
SELECT `'SCRAP$'`.order , `'SCRAPa$'`.Step , `'SCRAP$'`.Quantity , (SELECT SUM(`'ORDER$'`.Cost) FROM `'ORDER$'` `'ORDER$'` WHERE `'ORDER$'`.order = `'SCRAP$'`.Order and `'ORDER$'`.Step <= `'Scrap$'`.Sterp) FROM `'SCRAP$'` `'SCRAP$'`It merged the two queries in one bringing the total cost from Order table.
* Model2 - Will not bring the sum of the costs from order table.
Thank you,
Diogo Dalla