Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

Calculated column - duration between previous payment

Most of the time when I ask something is about a specific technical question, here I have a demand and I know even know how to start. Trying to start this new dashboard it's the first time that I'm stuck how to approach this. So in despair I would ask some help.

 

I have a classical payment table where we store id, organization_id (<- who receive the money), date, amount... you named it !

 

I have to build a dashboard where there is a matrix.
The v1 of this dashboard is to answer that : "I want to know the number of organizations where theirs last payment was the last month (so 2018-12 for the row 2019-01) | number where the last payment was M-2, M-3... to have a view of when the oarganizations where last active"


The prototype looks like this :

 M-1M-2M-3M-4M-5M-6M-[...]
        
Jan-19B3    G3 
Feb-19B4C4=B3-B4     
Mar-19       
Apr-19       
May-19       
Jun-19       
Jul-19       
Aug-19       
Sep-19       
oct.-19       
nov.-19       
Dec-19B14    G14 
        
B3 = # organizations where last payment was in 2018-12 the 2019-01-01 
G3 = # organizations where last payment was in 2018-07 the 2019-01-01 
B4 = # organizations where last payment was in 2019-01 the 2019-02-01 
B14 = # organizations where last payment was in 2019-11 the 2019-12-01 
G14 = # organizations where last payment was in 2019-06 the 2019-12-01 

 

I think that I have to make a new calculated column where for each rows in my payment table I have to calculate the number of months with the previous payment for the distinct organization. And don't know if it's the best approach and how to build this calculated column. My tries fail for now.

2 Replies

  • dax's avatar
    dax
    Community Support

    Hi gilHA,

    I am not clear about your requirement, what did you mean of “I want to know the number of organizations where theirs last payment was the last month (so 2018-12 for the row 2019-01) | number where the last payment was M-2, M-3... to have a view of when the oarganizations where last active”? If possible, could you please inform me in details(your sample data and your expecting output)?

    In addition, if your dataset sample is  like below, and you want to get result like below, you could try to use below expression

    previous =
    VAR previousm =
        DATEADD ( 'time'[ytime], -1, MONTH )
    RETURN
        CALCULATE (
            SUM ( 'time'[amount] ),
            FILTER ( 'time', 'time'[ytime] = previousm )
        ) - 'time'[amount]
    pre 6 month =
    VAR p6m =
        DATEADD ( 'time'[ytime], -6, MONTH )
    RETURN
        CALCULATE ( SUM ( 'time'[amount] ), FILTER ( 'time', 'time'[ytime] = p6m ) ) - 'time'[amount]

    Best Regards,

    Zoe Zhi

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi dax,

       

      Thank you for your help. I will try to be a bit more precise then.

       

      I follow the video I have mention earlier and calculated the previous payment date for each paiment ordered by organization and date. Then I calculated the number of month between the current and the later payment cheching first if the organization_id is the same, if not I add -1 as a value. It's not really what I'm looking for because I wanna check not exactly the last payement but id there was a payment the last month, or two month before... but it's a start.


      If we focus on the data of one unique organization that should look like this :

       

      idorganization_idamountdateprev_organization_idprev_id_paymentprev_datedelta_date
      2830649123452018-09-29 22:17:00789028306372018-09-29 22:17:00-1
      28309151234102018-09-30 00:44:00123428306492018-09-29 22:17:000
      28323911234402018-11-15 13:41:00123428309152018-09-30 00:44:002
      2832506123452018-12-07 14:07:00123428323912018-11-15 13:41:001
      28325881234102018-12-11 14:28:00123428325062018-12-07 14:07:001
      28326211234102019-01-07 14:34:00123428325882018-12-11 14:28:001
      2832656123452019-01-08 15:39:00123428326212019-01-07 14:34:001
      28326781234102019-01-09 17:44:00123428326562019-01-08 15:39:001
      283275112341002019-01-17 14:26:00123428326782019-01-09 17:44:001
      28327731234372019-03-21 14:56:00123428327512019-01-17 14:26:002


      So this organization was "active" (at least one payment) in september, nov, dec, jan amd mar.

       

      So the final table (if I have to filter on this particular organization, but obviously I want it on my full data) will look like this :

       

      DateM+1M+2M+3 
      01/09/20180  ← First payment receive
      01/10/20181  ← Had a payment last month
      01/11/201801 ← Last payment from 2 months ago
      01/12/20181   
      01/01/20191   
      01/02/20191   
      01/03/201901 ← Last payment from 2 months ago

       

      Is that a better explanation ?