236
Views
11
Comments
Months Filter
Question
Application Type
Reactive

I want to filter the data based on last 3 months,last 6 months and the current month

I have used the below filter 

If(Dashboard_Filters.Filter_Month_Type_Id = NullIdentifier(),True,If(Dashboard_Filters.Filter_Month_Type_Id =Entities.MonthType.Last3Months,AddMonths(CustomerPurchaseOrder.POReceivedDate,-3),If(Dashboard_Filters.Filter_Month_Type_Id=Entities.MonthType.Last6Months,AddMonths(CustomerPurchaseOrder.POReceivedDate,-6),If(Dashboard_Filters.Filter_Month_Type_Id=Entities.MonthType.Current_ThisMonth,AddMonths(CustomerPurchaseOrder.POReceivedDate,0),False),False),False))

But unable to achieve the filter, please guide me to achieve the filter

2023-10-21 19-42-11
Tousif Khan
Champion

Hello
Using the month function you will get the month  Month(AddMonths(CustomerPurchaseOrder.POReceivedDate,-1))

You can apply the same for different results

Try this I hope this will help.

Thanks 

UserImage.jpg
Vrushali Punekar

Hi,

You need to add the condition as per your requirement in the filter.

For e.g.

If(Dashboard_Filters.Filter_Month_Type_Id =Entities.MonthType.Last3Months,test.Months = Month(AddMonths(CustomerPurchaseOrder.POReceivedDate,-3)),

UserImage.jpg
Nihal Hegde

test is a date type attribute, test.Months is not possible

2022-09-27 05-23-26
Mohammad Shoeb

Hi Nihal,

Follow the correct statement for if conditions

if(condition,

if(Condition,true,false),

if(condition,true,false)

you might getting syntax issue.

Regards,

Shoeb

UserImage.jpg
Nihal Hegde

Thank you @Mohammad Shoeb 

2023-01-03 11-55-04
Suchita Khandelwal

There might be syntax error in your code as the filter mentioned in the question is correct.

2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi @Nihal Hegde ,

I doubt that you are applying the AddMonths to the correct date, and you are probably making this far more complex than it needs to be, and I find it astonishing it even is accepted by OS, as it doesn't even look like a correct expression evaluating to a boolean, and nowhere are you relating it to the date of today...

So you have Purchase Orders with a POReceivedDate.  And by choosing a filter option of X months, you only want to see orders with a ReceivedDate in the timeframe of X months before today, right ?

So your filter condition could be as simple as this :


Dashboard_Filters.Filter_Month_Type_Id  = NullIdentifier() 

or 

CustomerPurchaseOrder.POReceivedDate  >= AddMonths (CurrDate(),

If(Dashboard_Filters.Filter_Month_Type_Id=Entities.monthfilter.lastmonth, -1,

If(Dashboard_Filters.Filter_Month_Type_Id =Entities.monthfilter.last3months, -3, -6)))

....

Here's for a completely different approach :

If at all possible, I would try to pull any of this conditional hardcoded stuff out of my aggregate, to make it even simpler and more maintainable.

An example : you already have a static entity, just add an extra attribute of type integer with name months to that.  You probably have a dropdown to select this filter option, based on an aggregate retrieving the options from your static entity.  So, instead of storing the id of the choice, store the months value in a filter variable of type integer (let's call it MonthsToFilter).

Then, your filter becomes 

Dashboard_Filters. MonthsToFilter = 0 

or 

CustomerPurchaseOrder.POReceivedDate  >= AddMonths(CurrDate(), Dashboard_Filters. MonthsToFilter*-1)

If your users want other options to choose from in the future, it becomes a simple matter of changing your static, and the filter on the aggregate follows without any alterations.

....

And, you could take this even further, in the aggregate that feeds your dropdown of the static options, add a calculated attribute called "FromDate", with formula

DateTimeToDate(AddMonths(CurrDate(),MonthsToFilter*-1))

So now, you will need a filter variable of type date, and map the value of the calculated column of the dropdown to that.

Then your filter condition on your purchase order aggregate becomes even simpler

CustomerPurchaseOrder.POReceivedDate > Dashboard_Filters.FromDate

Dorine

2021-09-06 15-09-53
Dorine Boudry
 
MVP

all of the above is assuming you simply want a timespan of approximately 3 months counting back from today, not that you want actual calendar months or anything like that, i.e. i don't know what exactly your definition of "3 months" is

2023-02-06 14-27-11
André Smit

Hi @Nihal Hegde,

I've attached the OML file for your reference. I was trying to implement the solution that @Dorine Boudry suggested, and I found that her last method seemed like it would be the most efficient. However, I wasn't able to get it to work on my end, so I ended up going with method two.

I wanted to take a moment to express my gratitude to @Dorine Boudry for her helpful explanation. All credit goes to her for pointing me in the right direction.

In case it's helpful, I found that method two worked well for me, and I was able to achieve the desired result.

Best regards,
Andrew_Smith


NihalHedge_Sandbox.oml
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.