Is it possible to create dynamic grouping in Aggregate ?
Application Type
Reactive

Hi All,

In my reactive web application, I have used a switch button to make selection for daily or monthly records counts, the default is monthly. I have created an aggregate and then created three calculated attributes to extract year, month and day from a date and grouped them on year and month to get a count of records per month.

Now, to get daily records count, is there a way to dynamically create "group by day" using an If statement ? Or,  should I create a new aggregate ?

Thanks

Vaibhav Gijre

Hi Vaibhav,

yes it is possible, but you always have to weigh the cost of making it more complex / expensive to execute, against the cost of having to maintain several aggregates instead of one.

So what you do, is you make one more calculated column, with If conditions based on the switch button values, choosing the value of one of your 3 calculated columns.  And then you group on that one.

See attached oml

Dorine


EDIT : just to be complete, you don't really have to split it over several calculated columns, you can calculate all of it in one formula taking into account the switch value.

that calculated column would be something like

Year(SomeEntity.Date)
+ If(GroupBy = "D" or GroupBy = "M", "-" + If(Month(SomeEntity.Date)<10,"0","") + Month(SomeEntity.Date),"")
+ If(GroupBy = "D", "-" + If(Day(SomeEntity.Date)<10,"0","") + Day(SomeEntity.Date),"")
QDRGroupByWhatNow.oml

Thanks Dorine,

This works perfectly.

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