Filter amazon personalize availability based on a date range and stock on hand ( nullable value ) - amazon-personalize

I have around 500K items whose availability depends on the stock on hand and the availability date( available_on and discontinue_on ). I want to filter unavailable items from the recommendation, I expect something like this:
Include
Items.available_on <= $now AND
(Items.discountinue_on IS NULL OR Items.discountinue_on > $now ) AND
Items.stock_on_hand > 0
however, I could not figure out how to write the about expression in aws personalize filter.

Update
Dynamic filters now support range operators (i.e., <, <=, >, >=). However, IS NULL and grouping operators like parentheses are not supported. Therefore, the discontinue_on field should be populated with a valid date or a date in the extreme future for products that cannot be discontinued. The filter statement would then look something like this.
INCLUDE ItemID WHERE Items.available_on <= $now AND Items.discountinue_on > $now AND Items.stock_on_hand > 0
Below is the relevant portion of the prior answer that is still applicable but may be less ideal than the solution above.
There are a couple alternative approaches that will also work. First, you can use a single field in your items dataset that indicates whether the item is available or not (e.g., is_available). So a true/false value that represents the current state of 1/ being available, 2/ not discontinued, and 3/ with stock on hand. This means your application needs to update this flag for items when their availability status changes. In other words, when the item is discontinued or out of stock, change its is_available field value to false. This can be done using the PutItems API. Your filter becomes much simpler.
INCLUDE ItemID WHERE Items.is_available = "true"
Another approach would be to keep the available_on, discontinue_on, and stock_on_hand in your items dataset and filter expression but replace $now to a fixed/hard-coded value.
INCLUDE ItemID WHERE Items.available_on <= 20211105 AND Items.discontinue_on > 20211105 AND Items.stock_on_hand > 0
where 20211105 is the current date in YYYYMMDD format. You can add hours, minutes, seconds for more granularity. Of course, this means that the datetimes in your filter expression need to be regularly updated. This requires periodically creating a new filter with updated datetimes, switching your app to use the new filter, and then deleting the old filter. Essentially rotating your filter over time. This serverless app can make this process much easier.
https://github.com/james-jory/amazon-personalize-filter-rotator

Related

Find count of active users in the last 29 days in Tableau

Require assistance in calculating the Total Active Users from March 16 2020 to Feb 16 2020.
I have tried using calculated fields, but not getting the correct results. Please advise.
Thank you,
Nirmal
To find the number of unique values that appear in a field, say [user_code], you can use the COUNT DISTINCT function, COUNTD() as in COUNTD([user_code])
To restrict the data to a particular time range, one way is put your date field on the Filter shelf and choose the settings that include only the data rows you want — say the range from 2/16 to 3/16 as you stated.
Alternatively, you can push the filtering condition into the calculation with an IF function call, as in COUNTD(IF <data is relevant> THEN [user_code] END) Thus effectively combining the two techniques. That works because if there is no ELSE clause and the IF condition is False then the IF statement evaluates to null. Since COUNTD() silently ignores nulls, like other aggregation functions, the expression acts as if the irrelevant data rows were filtered.
So, for example,
COUNTD(IF [dates] >= #2/16/2020# AND [dates] <= #3/16/2020# THEN [user_code] END)
Will tell you then number of unique user codes during the period between 2/16 and 3/16. The DateDiff() function will probably be useful in more elaborate tests.
Finally, what if you want more flexibility? You could easily use Parameters or Filter controls to let the user choose the date range interactively.
If you want this calculation repeated for each possible day, showing the unique users in the preceding 30 day period, as some sort of rolling calculation, then you’ll need to learn about some more advanced features. Either multiple calculations as above for different time ranges, using Table Calculations, or some data prep and/or data padding with Tableau Prep Builder, Python or some other technique — mostly because in that scenario each data row contributes to multiple rolling counts, rather than one count when partitioning the data by some dimension.

Sorting Data by Latest Date, selecting top 10 and charting (v. 10.0.1)

This is the data table that I have created
I need to sort the data by 'April2017' in descending order and then select the top 10 projects.
When we select top10 basis April2017, the output should be
Instead what I get is
Here is what I've tried out so far,
Created a calculated field
Calculation1 = iif([Year_Month]=MAKEDATE(2017,4,1),[Claim Count],0)
Sorted Projects based on 'Calculation1'
Drag Project to Filter and select Top10 based on sum([Calculation1])
I am unable to understand how the top10 here is being derived.
Where am I going wrong?
The chart that I am trying to get should be similar to
Please help me with this problem.
You can filter to a selected portion of data in a calculation and use as desired. So create a calculated field called, say April_2017_Foobars, defined as:
if datetrunc('month', [Year_Month]) = #04/01/2017# then [Foobars] end
This field return [Foobars] for the April 2017 rows and null for other rows. Nulls are ignored by aggregate functions, so if you aggregate with SUM() or AVG() etc, the effect is to filter to April 2017 for that field alone.
Then you can use April_2017_Foobars for sorting and defining top filters for your Project field. This is a very general technique that is useful in all kinds of situations.
You can generalize it a bit to use a parameter for the special month rather than hard code it - or use an LOD calc to find the last month in your dataset if you always intend to use the latest month.
P.S. You can use the makedate() function instead of a date literal if you prefer and your data source supports that function. Might avoid any confusion about date literal formats being different in various countries.
create Calculation1 field: iif([Year_Month]="April 2017",[Number],0)
sort Project in descending order on Calculation1 Sum
drag Project to filters, and do Top > By Field > Top: 10 by Calculation1 Sum

Tableau - Filter/Parameter For Different Date Ranges

I am trying to set up a filter or parameter for different date ranges in Tableau, such as:
Previous Week
Previous 4-Weeks
Previous 8-Weeks
based on the most recent data in the database. Is this possible?
Edit:
I should have been more clear here.
Is it possible to only have these options in the filter and have it based on the maximum date in the database?
Update
Based on your comment and updated question, you can do it as you intend, though it isn't as straight-forward.
NOTE: I did this very quickly and with a random data set, so it will be important for you to test this thoroughly with your data set.
Steps:
Create a parameter control that the users will use to change the selected date range. I created this as a list of strings with values that I can use directly in a calculated (after simple casting):
Create a calculated field that you will use as a filter that references the selection of the parameter control. It tests to see if the difference (in weeks) between the maximum date in the view and the date of any given row is less than the value of the parameter.
Calculation: INT([Date Filter Parameter]) > DATEDIFF("week",ATTR([Date Field]),WINDOW_MAX(MAX([Date Field])))
Place the calculated field in the filter box and set it to True.
You will be able to filter your data like so:
Original Answer
Yup - that is built into Tableau.
Add your date to the filter and select the "Relative Date" option:
You can set the defaults - users can change these later:
Then just "Show Filter":

Default range for date range filter in tableau

I want to set the default range on a date filter to show me the last 10 days - so basically looking at the lastDate (max date) in the data and default filtering only on the last 10 days (maxDate - 10)
How it looks now:
I still would want to the see the entire range bar on the dashboard and give the user the ability to modify the selected range if he wants to. The maxDate changes after every data refresh so it has to be some sort of a condition that is applied to the filter.
How I want it to look (by default after every refresh of data - new dates coming in):
Any suggestions on how this can be done? I know I can use the relative date and show the data for last 10 days but that would modify the filter and create a drop down which I don't want.
Any suggestions are welcome!
One simple approach that does most of what you want is the following:
Create an integer valued parameter with a range from 1 to some max
you choose, say 100. Call it say num_days.
Show the parameter control on your dashboard as a slider, and give
it a nice title like "Number of days to display"
Create a boolean calculated field called Within_Day_Range defined as:
datediff('minute', [My_Date_Field], now()) < [num_days] * 24 * 60
Put Within_Day_Range on the filter shelf and select the value true.
This lets the user easily select how many days in the past to include, and works to the granularity of minutes (i.e. the last two days really means the last 48 hours, not starting at midnight yesterday). Adjust the calculated field if you want different behavior.
The main drawback of this approach as described so far is that it doesn't display the earliest date possible in the database because that is filtered out. Quick filters do an initial query to get the bounds, which has a performance cost -- so using the approach described here can avoid that query and thus load faster.
If you really need that information on your dashboard, you could create a different worksheet to get just the min([My_Date_Field]) and display that near your parameter control.

How do I write a TFS 2010 Work Item query clause whos value is a field value?

I think this question may be spawned from lack of knowledge, but here we go...
I am trying to write a new team query (using the new query option of team explorer, in VS 2010) what I want is fairly simple; essentially a list of work items whos [Completed Work] value exceeds the [Original Estimate] field value. In other words WIs that have exceeded their original estimates.
The VS 2010 view does not seem to have an option to show the WIQL being generated under the hood, so I'll have to describe what I have done/am trying to do via the VS 2010 UI.
Clauses are fairly standard to start;
Team Project = #Project
And Work Item type = Task
And State = [Any]
I have added a caluse (to remove any work items without an estimate)
And Orignial Estimate <> ''
I thought the next step would be simplicity itself; adding a clause along the lines of
And Completed Work > Original Estimate
But no matter how I try to write "Original Estimate" in the value filed of the UI (as Original Estimate, [Original Estimate] and many other variations) to date all I get is a line indicating a that Input string was not in a correct format.
Is this possible? I would have thought simple comparisons to the value of another WI field would be supported, are they? If it is possible what the he** is the syntax?
Thanks.
Update
I had a look at the Task template and confirmed that both Original Estimate and Remaining Work are doubles and have the following full names (should that be relivant)
Friendly Name Type Ref Name
Original Estimate Double Microsoft.VSTS.Scheduling.OriginalEstimate
Remaining Work Double Microsoft.VSTS.Scheduling.RemainingWork
You simply need the >= [Field] operator instead of the >= operator:
Original Estimate >= [Field] Completed
Work