Forum Discussion

astojanac's avatar
astojanac
Helper II
5 years ago

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

  • Hi,

    I think this will be easier to solve with a measure directly in the visual.

    • Ashish_Mathur's avatar
      Ashish_Mathur
      Super User

      Hi,

      Share the exact structure of your input data in a form that i can paste in an MS Excel file.

      • astojanac's avatar
        astojanac
        Helper II

        Hi, 

        Here is input sample:

        idstart_dateend_dateopeningmonthly paymentinteres rate
        A101/09/201401/09/2024539,05754000.003
        A201/09/201601/09/2021300,50030000.0025

         

         

        And here is output:

        ABCDEF
        idMonthOpeningPaymentInterestClosing
        A101/09/2014539,05754001601535,258
        A101/10/2014535,25854001590531,448
        A101/11/2014531,44854001578527,626
        A101/12/2014Closing previous month5400(Closing prev month C - payment D) * rateC+D-E
        A101/01/2015 5400  
        A101/02/2015 5400  
        A101/09/2024 5400  
              
              



        Thanks, I appreciate your expertise!