Forum Discussion

mbostrom_dtiq's avatar
mbostrom_dtiq
New Contributor II
5 years ago

Generate sequence of dates between 2 dates

i have a requirement to “fill in the gaps in time” per se on data from a system. Here is my use case:

A customer signed up with the company for $100 subscription monthly for 3 years. The company added services 6 months into the contract which bumped their subscription up to $120 / month, and again a couple months later. but then never again for a couple years. however our ERP only shows the effective dates based on the change. so the json from the system would look this this but I need to create records for every missing month using the previous month if no changes were made. Then when the next change made use that and generate the missing time between that month and subsequent months until the last change. this will allow us to show trending over time and the revenue for that customer by every month in which they have been a customer. what is the best way to achieve this? a parent customer can have multiple locations in which this could change for this example i’ve simplified it to just 1 customer with multiple records so i believe some level of grouping and min/max dates need to be used.

[
{
“Parent_Customer_Id”: 12345,
“Location_Site_ID”: 98765,
“Parent_Customer_Name”: “Acme”,
“Business_Name”: “Acme Store 1”,
“Monthly_Change_Tracking_Id”: 7,
“Effective_Date”: “2015-12-16T00:00:00.000”,
“Monthly_Revenue”: 100
},
{
“Parent_Customer_Id”: 12345,
“Location_Site_ID”: 98765,
“Parent_Customer_Name”: “Acme”,
“Business_Name”: “Acme Store 1”,
“Monthly_Change_Tracking_Id”: 21,
“Effective_Date”: “2016-06-16T00:00:00.000”,
“Monthly_Revenue”: 120
},
{
“Parent_Customer_Id”: 12345,
“Location_Site_ID”: 98765,
“Parent_Customer_Name”: “Acme”,
“Business_Name”: “Acme Store 1”,
“Monthly_Change_Tracking_Id”: 44,
“Effective_Date”: “2016-08-16T00:00:00.000”,
“Monthly_Revenue”: 130
},
{
“Parent_Customer_Id”: 12345,
“Location_Site_ID”: 98765,
“Parent_Customer_Name”: “Acme”,
“Business_Name”: “Acme Store 1”,
“Monthly_Change_Tracking_Id”: 55,
“Effective_Date”: “2020-12-16T00:00:00.000”,
“Monthly_Revenue”: 150
}
]

2 Replies

  • SriVinayaga's avatar
    SriVinayaga
    New Contributor II

    Didnt expect it to be so simple. Thank you very much @tstack. Appreciate your help.

  • bojanvelevski's avatar
    bojanvelevski
    Valued Contributor

    Try the following expression:

    $.filter((v k)=> v!= null)

    Map $ as target path.

  • darshthakkar's avatar
    darshthakkar
    Valued Contributor

    @mmindenhall: You can also use either of a filter snap or router snap.
    When you’re using either of these snaps, you’ll have to define a rule, like $first_name != null

    Have a mapper after filter and organize the data in the way you want, write it to a file/update the DB as per your use case.

  • cdmills's avatar
    cdmills
    New Contributor II

    This sounds like a job for the Conditional snap; it is essentially “if (condition) then map”.

    • bojanvelevski's avatar
      bojanvelevski
      Valued Contributor

      @cdmills
      The expression I sent is the one you need. Put it in a mapper and validate the result.