Data360 Analyze

 View Only
  • 1.  Filter Results for Last 7 Days

    Posted 05-26-2024 22:13

    Hi - Im trying to only show results from the last 7 days, from a dataset that goes back years. In the Filter node, the only options within Operator and Value ask for a specific date. Is there a different node or example scripting i could use to achieve this? 

    Nathan Schofield
    Telstra Corporation Limited
    Sydney NSW

  • 2.  RE: Filter Results for Last 7 Days

    Posted 05-27-2024 08:58


    Filter node won't work with dynamic date ranges. Depending on what is the data source, you might have 2 options:
    1. If data source is a database and depending on database type and how your datetime column is formatted, you can simply add where clause something like this (This is an Oracle syntax): WHERE Bill_Dt >= SYSDATE - 7.Google for other sql flavour examples like MSSQL etc. 

    2. If the data source isn't the database or you cannot make above example to work for some reason, use python transformation node and there are few methods to achieve the same using datetime module import inside the node. If you could post the screenshot of your date column how it looks like and what is the formatting, maybe we can help even better. 

    Irakli Chitishvili
    Data Trust Associates

  • 3.  RE: Filter Results for Last 7 Days

    Posted 05-29-2024 09:47

    Assuming the reference field in the input data has a data type of datetime, you can use the following script in a Transform node to filter the required records.

    Note, change the input field reference in the ProcessRecords Script (fields.test_Datetime in the example)

    #### Start of ConfigureFields Script:

    #Configure all fields from input 'in1' to be mapped
    #to the corresponding fields on the output 'out1'
    out1 += in1

    ## Debug fields
    ## Create a date-type field to display today's datetime
    out1.Current_Datetime = datetime.datetime

    ## Create a date-type field to display the datetime one week ago
    out1.One_Week_Ago = datetime.datetime
    ## End Debug fields

    ## Create a variable with today's date
    today =

    ## Specify the time as the start of the day
    start_Of_Day = datetime.time(00, 00, 00)

    ## Combine the date and time elements to form a datetime object
    start_Of_Today = datetime.datetime.combine(today, start_Of_Day)

    ## Create a timedelta variable that represents a period of 7 days
    one_Week_Period = datetime.timedelta(days=7)

    ## Calculate the datetime 7 days ago
    Datetime_one_week_Ago = start_Of_Today - one_Week_Period

    #### End of ConfigureFields Script:

    #### Start of ProcessRecords Script:

    ## Selectively output records if they are recent enough
    if fields.test_Datetime >= Datetime_one_week_Ago:
        out1 += in1
        ## Debug output fields
        out1.Current_Datetime = start_Of_Today
        out1.One_Week_Ago = Datetime_one_week_Ago
        ## End Debug output fields

        ## Write the record
        node.write(0, out1)

    End of ProcessRecords Script:

    You may also be interested in some of the examples in the Help documentation relating to Python scripting for datetime data types. See the following topic in your system's integrated Help documentation:

    Data360 Analyze Server Help > Migrating from LAE > What's changed? > BRAINscript to Python > Date, time and datetime functions

    The information is also available online for the latest version of the product here:

    Adrian Williams
    Precisely Software Inc.