Example (deprecated): Remove duplicates from connected dropdown options

Dear @yisrael-wix , would that be possible to remove duplicates from a combination of a text box (Heading1, entity) + dropdown (Select a period, period1) both stored in dataset in a dynamic page? So that when showing the dropdown list (Select a period), only the “period” entries corresponding to the Heading 1 (here the company) are displayed:


my current code currently only affects the period without taking into account the text value which is also a table field:

$w.onReady( function () {
wixData.query(“Entity_sales_data_input”)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w(“#dropdown3”).options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.period1);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return { label: curr, value: curr };
});
}
});
});