Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Aag
Contributor III
Contributor III

Nested calc help

Hello all, 

I have a measure field "Target"  for every month for Salesperson..  Measure field calc = avg(Target) 

I am having issue calculating YTD Target... I need to calculate  Avg( Avg(Jan Target), Avg(Feb Target))  So as the month progresses, it should automatically consider the average of next month in the YTD calculation. 

So I tested the below condition and this works.. and the result is as I expected.. But I have hardcoded monthnum here. I need to automatically do the same condition from Yearstart to max(date)... 

(Avg({<SalesYear={$(=Max(SalesYear))},MonthNum={1}>}Target)
+  Avg({<SalesYear={$(=Max(SalesYear))},MonthNum={2}>}Target))  
/ Max(Month(Salesdate))

The goal is not to hardcode the months.. it should automatically consider in YTD calculation. 

Please give me suggestions on how to resolve this. 

Labels (1)
1 Solution

Accepted Solutions
MikeA
Contributor III
Contributor III

I'd suggest an aggr to calculate the averages by month and then average the total for the salesperson -

avg({<SalesYear={$(=Max(SalesYear))},MonthNum={"<=$(max(MonthNum)+1)"}>}aggr(avg(Target),MonthNum,Salesperson))

MonthNum={"<=$(max(MonthNum)+1)"} is looking at the next month assuming you have current month selected, although you may need to consider what happens at year end.

View solution in original post

2 Replies
MikeA
Contributor III
Contributor III

I'd suggest an aggr to calculate the averages by month and then average the total for the salesperson -

avg({<SalesYear={$(=Max(SalesYear))},MonthNum={"<=$(max(MonthNum)+1)"}>}aggr(avg(Target),MonthNum,Salesperson))

MonthNum={"<=$(max(MonthNum)+1)"} is looking at the next month assuming you have current month selected, although you may need to consider what happens at year end.

Aag
Contributor III
Contributor III
Author

Works like a charm! Thanks a lot @MikeA . Appreciate it.