I used these formula to calculate number of months between two dates.
Whereas,
Start Date - LastPrincipalChangeDate
End Date - DateofTransaction
IF(YEAR([LastPrincipalChangeDate])=YEAR([DateofTransaction]),
MONTH([DateofTransaction])-MONTH([LastPrincipalChangeDate]),IF((YEAR([LastPrincipalChangeDate])+1)=YEAR([DateofTransaction]),
(12-MONTH([LastPrincipalChangeDate]))+MONTH([DateofTransaction]),(12-MONTH([LastPrincipalChangeDate]))+MONTH([DateofTransaction])+
((YEAR([DateofTransaction])-YEAR([LastPrincipalChangeDate])-1)*12)
))
+
IF(
Day([LastPrincipalChangeDate])<=DAY([DateofTransaction]),
,0,-1)
When I tried to put the IF statements in different VCs, it seems Appsheet wonโt allow me to multiply the difference in years by 12.
Appreciate anyoneโs response
Regards,
Edison
Solved! Go to Solution.
Nothing wrong with the above, but, OH MY GOODNESS, Finally Figured it out! The problem was not the Formula. But the other VCs referring to the VC containing the formula. My bad, I went all through this trouble just to find that out.
(
((year([DateofTransaction]) * 12) + month([DateofTransaction])) - ((year([LastPrincipalChangeDate]) * 12) + month([LastPrincipalChangeDate]))
)
+IF(
OR(
Day([LastPrincipalChangeDate])<=DAY([DateofTransaction]),
AND(MONTH([LastPrincipalChangeDate])=MONTH([DateofTransaction]),
YEAR([LastPrincipalChangeDate])=YEAR([DateofTransaction]))
)
,
0,
-1)
FINALLY, itโs now resolved. Sorry for the trouble I caused you, and thanks for your help Steve! Appreciate it very much!
Well at least, I get to learn a shorter expression from you! Haha
Perhaps not significant, thereโs an extraneous comma:
That suggests you tried just the following in a virtual column?
((YEAR([DateofTransaction])-YEAR([LastPrincipalChangeDate])-1)*12)
If not, would you?
Hi Steve!
Thanks for showing your interest on my question! Appreciate it a lot.
Yes I did that, and I feel like that seems to be the problem.
Amazing that youโve come up with a shorter formula! However,
when I tried it out, it still gives me the same error. I dissected your formula, and found out that (please expand each bullet):
And to add some context, Iโm not sure if these are factors for the error?
Iโm just concerned the fact that, thereโs nothing in the INFO > ERRORS to guide me on how I can troubleshoot this issue when I get that error in my app.
And that, the expression builder seems to tell me that, my expressions are not erroneous.
Maybe this is a bug?
Or it would really be helpful if anyone can give me an alternative formula to compute for months. I tried some month calculation formula in this forum, but were not working as I intended (e.g. some only limits itโs count to a year)
I suspect the problem is related to LastPrincipalChangeDate being a virtual column. Please provide a screenshot of its complete app formula expression.
MAX(
SELECT(Daily Loan Transaction[DateofTransaction],
AND(
[PNNo.]=[_THISROW].[PNNo.],
[DateofTransaction]<[_THISROW].[DateofTransaction],
OR(NOT([LoanReceivable]=0),ISNOTBLANK([LoanReceivable]))
))
+
LIST([PNNo.].[DateAvailed])
)
Basically, what Iโm trying to compute here is to get the max date in the same table , with the following condition:
Then after those are filtered, get the MAX date. together with the Date Availed under the Parent Table (in cases, thereโs no record under the filtered table.
Since youโve mentioned it, I tried using ANY instead of MAX and it worked. Maybe then, Iโm using MAX expression incorrectly? although the expression builder doesnt meantion of any errors.
Thank you for taking the time to solve this with me.
So itโs working as you want?
Hi steve,
No not yet, was just appreciating your effort to help me out until now.
Going back here, what happens when you click the Test button?
Please do the following:
Create a virtual column with an app formula of YEAR([DateofTransaction])
. Use the Test button and review the results for unexpected values. Do not Save the expression or leave Expression Assistant.
Replace the expression from (1) with YEAR([LastPrincipalChangeDate])
. Again, use the Test button and review the results for oddities. Do not leave Expression Assistant.
Repeat the process again with the expression YEAR([DateofTransaction]) * 12
.
And repeat again with the expression YEAR([LastPrincipalChangeDate]) * 12
.
Press the Cancel button to leave Expression Assistant.
Delete this new virtual columnโit was only for testing.
Stop at the first step that produces unexpected results and post a screenshot that demonstrates those results.
Yeahโฆ Thatโs not surprisingโฆ
Nothing wrong with the above, but, OH MY GOODNESS, Finally Figured it out! The problem was not the Formula. But the other VCs referring to the VC containing the formula. My bad, I went all through this trouble just to find that out.
(
((year([DateofTransaction]) * 12) + month([DateofTransaction])) - ((year([LastPrincipalChangeDate]) * 12) + month([LastPrincipalChangeDate]))
)
+IF(
OR(
Day([LastPrincipalChangeDate])<=DAY([DateofTransaction]),
AND(MONTH([LastPrincipalChangeDate])=MONTH([DateofTransaction]),
YEAR([LastPrincipalChangeDate])=YEAR([DateofTransaction]))
)
,
0,
-1)
FINALLY, itโs now resolved. Sorry for the trouble I caused you, and thanks for your help Steve! Appreciate it very much!
Well at least, I get to learn a shorter expression from you! Haha
OUT-FRIKKINโ-STANDING!!! Well done!
For my own clarity, I reformatted your expression. Iโm including it here just for my reference:
(
IF(
(
YEAR([LastPrincipalChangeDate])
= YEAR([DateofTransaction])
),
(
MONTH([DateofTransaction])
- MONTH([LastPrincipalChangeDate])
),
IF(
(
(YEAR([LastPrincipalChangeDate]) + 1)
= YEAR([DateofTransaction])
),
(
(12 - MONTH([LastPrincipalChangeDate]))
+ MONTH([DateofTransaction])
),
(
(12 - MONTH([LastPrincipalChangeDate]))
+ MONTH([DateofTransaction])
+ (
(
YEAR([DateofTransaction])
- YEAR([LastPrincipalChangeDate])
- 1
)
* 12
)
)
)
)
+ IF(
(
DAY([LastPrincipalChangeDate])
<= DAY([DateofTransaction])
),
,
0,
-1
)
)
Or just try this (TEST THOROUGHLY!!!๐
(
((year([DateofTransaction]) * 12) + month([DateofTransaction]))
- ((year([LastPrincipalChangeDate]) * 12) + month([LastPrincipalChangeDate]))
)
User | Count |
---|---|
44 | |
29 | |
22 | |
20 | |
14 |