Hello,
How do I filter a dropdown to only show current month and the next months?
Solved! Go to Solution.
Create a numbered collection like below
Collect(col_months,Calendar.MonthsLong());
ForAll(col_months,
Collect(colNumberedMonths,
Last(FirstN(AddColumns(col_months,
"RowNumber",
CountRows(colNumberedMonths)+1
),
CountRows(colNumberedMonths)+1
)
)
)
)
and then in Items property, Filter(colNumberedMonths,RowNumber>=Month(Today()))
Hi @anonymia25,
Based on the issue that you mentioned, do you want to display the current month and next month in a Dropdown?
Please set the Items property as below:
Table({Month:"CurrentMonth:"&Month(Today())},{Month:"NextMonth:"&Month(DateAdd(Today(), 1, Months))})
Thought this would be simple, but ended up creating a collection that you'd have to create OnStart and add to Item propery of the dropdown
Clear(colMonths);;
ClearCollect(
NumberCollection;
"1";
"2";
"3";
"4";
"5";
"6";
"7";
"8";
"9";
"10";
"11";
"12"
);;
ForAll(
FirstN(
NumberCollection;
12 - Value(
Text(
Today();
"mm"
)
)
);
Collect(
colMonths;
{
Number: Value(
Text(
Today();
"mm"
)
) + ThisRecord.Value;
Month: Text(
DateAdd(
Today();
Value(ThisRecord.Value);
Months
);
"mmm"
)
}
)
)
In your App OnStart or Screen OnVisible, create a collection as:
Collect(AllMonths,Calendar.MonthsLong())
In your DropDown control, add Items as AllMonths and Default as Text(Today(),"mmmm")
Hi @v-qiaqi-msft,
Yes, I wanted to display the current month and the next months, for example this current month is July so the dropdown will list July until December..
How do I make the formula automatically calculate the current and the next months?
Thanks!
Hi, @happyume
Your method is simple and easy to understand but I am wondering if the previous months can be hidden from the list? Meaning only show the current and future months? Thank you so much.
Hi @anonymia25,
I think you have something misunderstanding with my solution. It is dynamically based on the Today().
Just imagine that the current date is 1/5/2021, the Dropdown will always display 1 and 2. So as the following days.
The Today() function changes dynamically based on the time flies.
I think they want the dropdown to display todays month, and all the other months of this year between this month and the end of the year. The only solution I found is to create 2 collections on start, needed to determine the amount of months to be added to the collection, and to assign the appropiate month name.
Create a numbered collection like below
Collect(col_months,Calendar.MonthsLong());
ForAll(col_months,
Collect(colNumberedMonths,
Last(FirstN(AddColumns(col_months,
"RowNumber",
CountRows(colNumberedMonths)+1
),
CountRows(colNumberedMonths)+1
)
)
)
)
and then in Items property, Filter(colNumberedMonths,RowNumber>=Month(Today()))
@KvB1 yes that is what i meant, and i have tried your solution but turns out there is error
User | Count |
---|---|
258 | |
111 | |
95 | |
48 | |
41 |