I would use these to create categorical column to label latest xx days, months, year and use it in the data filter.
If( :Date >= Date DMY( 1, Month( Col Max( :Date ) ), Year( Col Max( :Date ) ) - 1 ),
"Yes",
"No"
)
If( Col Max( :Date ) - :Date <= In Days( 30 ),
"latest 30 days"
)
You may modify this for the latest 6 months
If(
:Date >= Date DMY( 1, Month( Col Max( :Date ) ), Year( Col Max( :Date ) ) )
-In Years( 0.5 ),
"Yes",
"No"
)
For Labeling the latest X label
I would use this as example of latest 2 lot ID/cycle.
1. Reassign lot or Cycle by number
If( Row() == 1,
1,
If( :Start Date == Lag( :Start Date ),
Lag( :cycle ),
Lag( :cycle ) + 1
)
)
or this
If( Row() == 1,
1,
If( :lot ID == Lag( :lot ID ),
Lag( :cycle 2 ),
Lag( :cycle 2 ) + 1
)
)
Then, create this formula to label the latest xx ID or Cycle (2 in this example)
If( Col Max( :cycle ) - :cycle < 2,
"latest 2 cycles"
)
Alternatively, you can modify this script to run on your data table.
However, you need to rerun this script every time the data is updated. Thus, I prefer the one above.
last_no = 2;
// Define your column names
timestampCol = "Start Date"; // Replace with your actual timestamp column name
categoryCol = "lot ID"; // Replace with your actual category column name
// Reference the current data table
dt = Current Data Table();
// Create a summary table with the latest timestamp per category
dtSummary = dt << Summary(
Group( column(categoryCol) ),
Max( column(timestampCol) ),
Link to original data table(0),
Output Table Name("LatestPerCategory")
);
// Sort the summary table by latest timestamp descending
dtSummary << Sort(
By( column("Max(" || timestampCol || ")") ),
Order(Descending),
Replace Table(1)
);
// Get the top 2 categories
latestCategories = {};
For( i = 1, i <= last_no, i++,
Insert Into( latestCategories, dtSummary:lot ID[i] )
);
// Add a new column to flag the latest 5 categories
dt << New Column("Is Latest " ||char(last_no),
Character,
Formula( If( Contains( latestCategories, :lot ID ), "Yes", "No" ) )
);
// Optional: Close the summary table
Close( dtSummary, NoSave );
Here is how my test data look like
