I am trying to calculate the cost of sales under First-in-first-out method. The cost could be calculated by excel, which is in column N in the "Results" file. However, I am not sure how I could use Alteryx to do the same thing.
Any help is much appreciated. Thanks in advance.
Cheers,
Austin
Solved! Go to Solution.
@Danilang and @DavidP, thanks a lot!
The logic of the last formula may not seem intuitive. I would definitely love to see other approach that would be more straightforward to get the results.
I will try to divide the formula into different parts. You may also use the "Evaluate Formula" Function in excel to simplify the formulas.
Let's take the formula in cell M4 as an example:
=SUMPRODUCT(--(-SUM($L$3:L4)>I$3:I4),-SUM($L$3:L4)-$I$3:I4,K$3:K4)-SUM($M$3:M3)
1st part: --(-SUM($L$3:L4)>I$3:I4):
= {If sum(L3:L4) > I3, then = 1, else 0 ; If sum(L3:L4) >I4, then = 1, else 0}
The results of the first part would be {1;0}
2nd part: -SUM($L$3:L4)-$I$3:I4,K$3:K4
= {-SUM(L3:L4) - I3 ; SUM(L3:L4) - I4}, {K3 ; K4}
= {100-0 ;100-100}, {K3 ; K4},
= {100;0},{K3;K4}
= {100;0}, {8;0}
3rd part: -SUM($M$3:M3)
= 0
So, adding all the parts will be equal to SUMPRODUCT( {1;0}, {100;0), {8;0} ) - 0
=( 1*100*8 + 0*0*0 ) - 0
= 800
Using the same logic, the formula in cell M9 =SUMPRODUCT(--(-SUM($L$6:L9)>I$6:I9),-SUM($L$6:L9)-$I$6:I9,K$6:K9)-SUM($M$6:M8)
= SUMPRODUCT ( {1;1;1;0} , {150;50;50;0}, {150;0;10;0} ) - SUM(M6:M8)
= ( 1*150*150 + 1*50*0 + 1*50*10 + 0*0*0 ) - 15000
= 8000
The logic is to calculate the cumulative total cost of sales starting from the beginning by SUMPRODUCT(--(-SUM($L$6:L9)>I$6:I9),-SUM($L$6:L9)-$I$6:I9,K$6:K9) and then subtract the previous cost of sales up to last transaction with - SUM($M$6:M8). So, the remaining balance would be the cost of sales for that particular transaction. Hope that is clearer.
I try to highlight the reply in different colors but seems my reply was not updated. Please see the screenshot below:
The logic of the last formula may not seem intuitive. I would definitely love to see other approach that would be more straightforward to get the results.
I try to divide the formula into different parts below. You may also use "Evaluate formula" function in excel to simplify the formula as well.
Let's take the formula in cell M4 as an example:
=SUMPRODUCT(--(SUM($L$3:L4)>$I$3:I4),-SUM($L$3:L4)-$I$3:I4,$K$3:K4)-SUM($M$3:M3)
1st part: --(SUM($L$3:L4)>$I$3:I4)
= {IF SUM($L$3:L4) > I3, THEN = 1, ELSE 0; IF SUM($L$3:L4) > I4, THEN = 1, ELSE 0}
= {1;0}
2nd part: -SUM($L$3:L4)-$I$3:I4,$K$3:K4
= {-SUM($L$3:L4) - I3 ; -SUM($L$3:L4) - I4} , {$K$3 ; K4}
= {100-0 ; 100-100}, {8 ; 0}
= {100 ; 0} , {8 ; 0}
3rd part: -SUM($M$3:M3)
= 0
So, adding all parts will equal to SUMPRODUCT( {1;0} , {100;0} , {8;0} ) - 0
= (1*100*8 + 0*0*0) - 0
= 800
Using the same logic, the formula in cell M9 =SUMPRODUCT(--(-SUM($L$6:L9)>$I$6:I9),-SUM($L$^:L9)-$I$6:I9,$K$6:K9)-SUM($M$6:M8)
=SUMPRODUCT ( {1;1;1;0} , {150;50;50;0} , {150;0;10;0} ) - SUM(M6:M8)
= ( 1*150*150 + 1*50*0 + 1*50*10 + 0*0*0 ) - 15000
= 8000
The logic is to calculate the cumulative total cost of sales starting from the beginning by SUMPRODUCT(--(-SUM($L$6:L9)>$I$6:I9),-SUM($L$6:L9)-$I$6:I9,$K$6:K9) and subtract the previous cost of sales up to the last transaction with -SUM($M$6:M8). So, the remaining balance would be the non-cumulative cost of sales for that particular transaction. Hope this is clearer.
The logic of the last formula may not seem intuitive. I would definitely love to see other approach that would be more straightforward to get the results.
I try to divide the formula into different parts below. You may also use "Evaluate formula" function in excel to simplify the formula as well.
Let's take the formula in cell M4 as an example:
=SUMPRODUCT(--(SUM($L$3:L4)>$I$3:I4),-SUM($L$3:L4)-$I$3:I4,$K$3:K4)-SUM($M$3:M3)
1st part: --(SUM($L$3:L4)>$I$3:I4)
= {IF SUM($L$3:L4) > I3, THEN = 1, ELSE 0; IF SUM($L$3:L4) > I4, THEN = 1, ELSE 0}
= {1;0}
2nd part: -SUM($L$3:L4)-$I$3:I4,$K$3:K4
= {-SUM($L$3:L4) - I3 ; -SUM($L$3:L4) - I4} , {$K$3 ; K4}
= {100-0 ; 100-100}, {8 ; 0}
= {100 ; 0} , {8 ; 0}
3rd part: -SUM($M$3:M3)
= 0
So, adding all parts will equal to SUMPRODUCT( {1;0} , {100;0} , {8;0} ) - 0
= (1*100*8 + 0*0*0) - 0
= 800
Using the same logic, the formula in cell M9 =SUMPRODUCT(--(-SUM($L$6:L9)>$I$6:I9),-SUM($L$^:L9)-$I$6:I9,$K$6:K9)-SUM($M$6:M8)
=SUMPRODUCT ( {1;1;1;0} , {150;50;50;0} , {150;0;10;0} ) - SUM(M6:M8)
= ( 1*150*150 + 1*50*0 + 1*50*10 + 0*0*0 ) - 15000
= 8000
The logic is to calculate the cumulative total cost of sales starting from the beginning by SUMPRODUCT(--(-SUM($L$6:L9)>$I$6:I9),-SUM($L$6:L9)-$I$6:I9,$K$6:K9) and subtract the previous cost of sales up to the last transaction with -SUM($M$6:M8). So, the remaining balance would be the non-cumulative cost of sales for that particular transaction. Hope this is clearer.
Let's take the formula in cell M4 as an example:
=SUMPRODUCT(--(-SUM($L$3:L4)>$I$3:I4),-SUM($L$3:L4)-$I$3:I4,$K$3:K4)-SUM($M$3:M3)
The logic of the last formula may not seem intuitive. I would definitely love to see other approach that would be more straightforward to get the results.
I try to divide the formula into different parts below. You may also use "Evaluate formula" function in excel to simplify the formula as well.
Let's take the formula in cell M4 as an example:
=SUMPRODUCT(--(SUM($L$3:L4)>$I$3:I4),-SUM($L$3:L4)-$I$3:I4,$K$3:K4)-SUM($M$3:M3)
1st part: --(SUM($L$3:L4)>$I$3:I4)
= {IF SUM($L$3:L4) > I3, THEN = 1, ELSE 0; IF SUM($L$3:L4) > I4, THEN = 1, ELSE 0}
= {1;0}
2nd part: -SUM($L$3:L4)-$I$3:I4,$K$3:K4
= {-SUM($L$3:L4) - I3 ; -SUM($L$3:L4) - I4} , {$K$3 ; K4}
= {100-0 ; 100-100}, {8 ; 0}
= {100 ; 0} , {8 ; 0}
3rd part: -SUM($M$3:M3)
= 0
So, adding all parts will equal to SUMPRODUCT( {1;0} , {100;0} , {8;0} ) - 0
= (1*100*8 + 0*0*0) - 0
= 800
Using the same logic, the formula in cell M9 =SUMPRODUCT(--(-SUM($L$6:L9)>$I$6:I9),-SUM($L$6:L9)-$I$6:I9,$K$6:K9)-SUM($M$6:M8)
=SUMPRODUCT ( {1;1;1;0} , {150;50;50;0} , {150;0;10;0} ) - SUM(M6:M8)
= ( 1*150*150 + 1*50*0 + 1*50*10 + 0*0*0 ) - 15000
= 8000
The logic is to calculate the cumulative total cost of sales starting from the beginning by SUMPRODUCT(--(-SUM($L$6:L9)>$I$6:I9),-SUM($L$6:L9)-$I$6:I9,$K$6:K9) and subtract the previous cost of sales up to the last transaction with -SUM($M$6:M8). So, the remaining balance would be the non-cumulative cost of sales for that particular transaction. Hope this is clearer.
The logic of the last formula may not seem intuitive. I would definitely love to see other approach that would be more straightforward to get the results.
I try to divide the formula into different parts below. You may also use "Evaluate formula" function in excel to simplify the formula as well.
Let's take the formula in cell M4 as an example:
=SUMPRODUCT(--(SUM($L$3:L4)>$I$3:I4),-SUM($L$3:L4)-$I$3:I4,$K$3:K4)-SUM($M$3:M3)
1st part: --(SUM($L$3:L4)>$I$3:I4)
= {IF SUM($L$3:L4) > I3, THEN = 1, ELSE 0; IF SUM($L$3:L4) > I4, THEN = 1, ELSE 0}
= {1;0}
2nd part: -SUM($L$3:L4)-$I$3:I4,$K$3:K4
= {-SUM($L$3:L4) - I3 ; -SUM($L$3:L4) - I4} , {$K$3 ; K4}
= {100-0 ; 100-100}, {8 ; 0}
= {100 ; 0} , {8 ; 0}
3rd part: -SUM($M$3:M3)
= 0
So, adding all parts will equal to SUMPRODUCT( {1;0} , {100;0} , {8;0} ) - 0
= (1*100*8 + 0*0*0) - 0
= 800
Using the same logic, the formula in cell M9 =SUMPRODUCT(--(-SUM($L$6:L9)>$I$6:I9),-SUM($L$6:L9)-$I$6:I9,$K$6:K9)-SUM($M$6:M8)
=SUMPRODUCT ( {1;1;1;0} , {150;50;50;0} , {150;0;10;0} ) - SUM(M6:M8)
= ( 1*150*150 + 1*50*0 + 1*50*10 + 0*0*0 ) - 15000
= 8000
The logic is to calculate the cumulative total cost of sales starting from the beginning by SUMPRODUCT(--(-SUM($L$6:L9)>$I$6:I9),-SUM($L$6:L9)-$I$6:I9,$K$6:K9) and subtract the previous cost of sales up to the last transaction with -SUM($M$6:M8). So, the remaining balance would be the non-cumulative cost of sales for that particular transaction. Hope this is clearer.
The logic of the last formula may not seem intuitive. I would definitely love to see other approach that would be more straightforward to get the results.
I try to divide the formula into different parts below. You may also use "Evaluate formula" function in excel to simplify the formula as well.
Let's take the formula in cell M4 as an example:
=SUMPRODUCT(--(SUM($L$3:L4)>$I$3:I4),-SUM($L$3:L4)-$I$3:I4,$K$3:K4)-SUM($M$3:M3)
1st part: --(SUM($L$3:L4)>$I$3:I4)
= {IF SUM($L$3:L4) > I3, THEN = 1, ELSE 0; IF SUM($L$3:L4) > I4, THEN = 1, ELSE 0}
= {1;0}
2nd part: -SUM($L$3:L4)-$I$3:I4,$K$3:K4
= {-SUM($L$3:L4) - I3 ; -SUM($L$3:L4) - I4} , {$K$3 ; K4}
= {100-0 ; 100-100}, {8 ; 0}
= {100 ; 0} , {8 ; 0}
3rd part: -SUM($M$3:M3)
= 0
So, adding all parts will equal to SUMPRODUCT( {1;0} , {100;0} , {8;0} ) - 0
= (1*100*8 + 0*0*0) - 0
= 800
Using the same logic, the formula in cell M9 =SUMPRODUCT(--(-SUM($L$6:L9)>$I$6:I9),-SUM($L$6:L9)-$I$6:I9,$K$6:K9)-SUM($M$6:M8)
=SUMPRODUCT ( {1;1;1;0} , {150;50;50;0} , {150;0;10;0} ) - SUM(M6:M8)
= ( 1*150*150 + 1*50*0 + 1*50*10 + 0*0*0 ) - 15000
= 8000
The logic is to calculate the cumulative total cost of sales starting from the beginning by SUMPRODUCT(--(-SUM($L$6:L9)>$I$6:I9),-SUM($L$6:L9)-$I$6:I9,$K$6:K9) and subtract the previous cost of sales up to the last transaction with -SUM($M$6:M8). So, the remaining balance would be the non-cumulative cost of sales for that particular transaction. Hope this is clearer.
I try to highlight the formula in the above reply but not sure why it does not work. Hope the above reply is clear enough for you. Thanks!
Hi @AustinLeung
I am trying to implement it, but I am a bit confused.
Why is it {1,0} in the first part?
SUM($L$3:L4) > I3 -> -100 > 0 -> False -> 0
SUM($L$3:L4) > I4 -> -100 > 100 -> False -> 0
So it should be {0,0} and that's also what I get in the Designer when I implement it.
I double checked it in Excel. If I just run "=SUM($L$3:L4) > I3" in a formula, I get "false", same with the second statement.