Calculate in dependance to other rows

zehbart

New member
Joined
Mar 15, 2021
Messages
5
Reaction score
0
Points
0
Excel Version(s)
office365
Hello,

below you can see a part of a bigger table with about 30.000 rows and many different 'ReceiptNo's. The column 'FinalAmount' is usually simplay calculated by dividing 'Amount' by 100.

However, if the 'UnitType' is 5, the FinalAmount for all rows with the same 'ReceiptNo' and and a Time which is before the time of the row with 'UnitType' 5 should be 0.00.

In this example there is UnitType 5 in row 9. So, the FinalAmount in row 1-8 should be 0.00, since the ReceiptNo is the same and the Time is smaller than in row 9.

Does anyone have an idea how to implement this into the calcualtion of 'FinalAmount'?

Thanks already in advance
zehbart


TimeUnitTypeReceiptNoProduct IDAmountFinalAmount
08:28:0905712454544.54
08:28:091573401951.95
08:28:091573112292.29
08:28:091573253453.45
08:28:09057315780.78
08:28:090573952652.65
08:28:092570156615.66
08:28:106570-1-0.01
08:28:2655704544.54
08:28:2905712454544.54
08:28:291573401951.95
08:28:291573112292.29
08:28:291573253453.45
08:28:30057315780.78
08:28:300573952652.65
08:28:302570156615.66
08:28:306570-1-0.01
 
In the attached (it would be easier for us if you had attached one) is a formula in column F - in row 2 it's:
Code:
=IF(AND(COUNTIFS($B$2:$B$18,5,$C$2:$C$18,C2)>0,A2<MIN(IF((($B$2:$B$18=5)*($C$2:$C$18=C2))=1,$A$2:$A$18))),0,$E2/100)
For your understanding, that formula has been derived from the columns H:J which of course you don't need.

Would there ever be a case where two or more unit types of value 5 would be present for the same receipt number at different times? If so which of the times should be used to bring the Final Amount down to zero? The earliest or the latest?
 

Attachments

  • ExcelGuru11088.xlsx
    13.5 KB · Views: 8
Last edited:
Thanks, p45cal. Actually the table-part comes directly from a power query table. I am looking for a solution to solve this matter with power query. Sorry for the misunderstanding.
 
In the attached is a Power Query offering on Sheet1 (2).
It should work fine if there's only one Type 5 per receipt no. but may need a tweak, one way or the other (max/min), so again:
Would there ever be a case where two or more unit types of value 5 would be present for the same receipt number at different times? If so which of the times should be used to bring the Final Amount down to zero? The earliest or the latest?
I've made no attempt to make the Mcode more elegant/shorter.
 

Attachments

  • ExcelGuru11088b.xlsx
    26.5 KB · Views: 11
I tried to break down this issue more into detail. What I would need is custom column in power query that checks if there is any row which with the same ReceiptNo and a time that is bigger than in the actual row. Hope this is more clear now.
 
that looks great, thank you!
 
And No, there won't be a case where two or more unit types of value 5 would be present for the same receipt number at different times. Your solution works for me, thanks again.
 
Back
Top