Forum Discussion
astojanac
5 years agoHelper II
Dynamic calculated columns based on previous records
Hi everyone,
I need help with one DAX for calculated column.
Down below is example:
I have Date, the First Opening Value and Payment (green fields). All other field depends one of another.
Here is my test formula, but it doesn't work 😞
test closing =
var _max =
MAXX(
filter('Payment Schedule*',
'Payment Schedule*'[Opening LL 1 mesec]<>0 && 'Payment Schedule*'[Lease no]=EARLIER('Payment Schedule*'[Lease no])),
'Payment Schedule*'[Start month])
var _maxamt =
minx(filter('Payment Schedule*','Payment Schedule*'[Start month]=_max && 'Payment Schedule*'[Lease no]=EARLIER('Payment Schedule*'[Lease no])),
'Payment Schedule*'[Opening LL 1 mesec]- 'Payment Schedule*'[Payment]+'Payment Schedule*'[Kamata 1 mesec])
var amt_previuos = CALCULATE(_maxamt, FILTER('Payment Schedule*', 'Payment Schedule*'[Start month]= DATEADD('Payment Schedule*'[Start month],-1,MONTH) && 'Payment Schedule*'[Lease no]=EARLIER('Payment Schedule*'[Lease no])))
var _maxMonth = maxx(filter('Payment Schedule*','Payment Schedule*'[Start month]<=earlier('Payment Schedule*'[Start month])),'Payment Schedule*'[Start month])
return
IF(
'Payment Schedule*'[Opening LL 1 mesec]<>0, 'Payment Schedule*'[Opening LL 1 mesec]-'Payment Schedule*'[Payment]+'Payment Schedule*'[Kamata 1 mesec],
if(_maxMonth<=_max,
('Payment Schedule*'[Opening LL 1 mesec]-'Payment Schedule*'[Payment]+'Payment Schedule*'[Kamata 1 mesec]),
amt_previuos +
sumx(
filter('Payment Schedule*','Payment Schedule*'[Start month]>_max && 'Payment Schedule*'[Start month]<=_maxMonth),
(amt_previuos - 'Payment Schedule*'[Payment]) *
RELATED('Lease details'[Interest rate Monthly])*'Payment Schedule*'[broj dana za obracun kamate]/30.416))
)
Thanks in advance
14 Replies
- Ashish_MathurSuper User
Hi,
I think this will be easier to solve with a measure directly in the visual.
- astojanacHelper II
Hi Ashish_Mathur ,
Thank you for your reply.May I ask you for help with measures?
Thanks in advance
- Ashish_MathurSuper User
Hi,
Share the exact structure of your input data in a form that i can paste in an MS Excel file.
- astojanacHelper II
Hi,
Here is input sample:
id start_date end_date opening monthly payment interes rate A1 01/09/2014 01/09/2024 539,057 5400 0.003 A2 01/09/2016 01/09/2021 300,500 3000 0.0025 And here is output:
A B C D E F id Month Opening Payment Interest Closing A1 01/09/2014 539,057 5400 1601 535,258 A1 01/10/2014 535,258 5400 1590 531,448 A1 01/11/2014 531,448 5400 1578 527,626 A1 01/12/2014 Closing previous month 5400 (Closing prev month C - payment D) * rate C+D-E A1 01/01/2015 5400 A1 01/02/2015 5400 A1 01/09/2024 5400
Thanks, I appreciate your expertise!