Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello. I want to show gross sales only for 2011 year by using sum and if. Can someone tell me why is this function wrong and write down the correct function?
Thank you in advance.
You can't sum a sum, so unfortunately that won't work, regardless of the if() condition. You'll have to either use aggr() for the internal sum or re-write the formula to not use a nested aggregation.
This doesn't appear to be wrong, assuming [Gross sales] is a field in your application. Note that this will not ignore selections on any fields, so it will only work if no selections have been made or the selections made do not interfere with the sum. If Gross sales is an existing measure, this may not work because of a nested aggregation.
Note that this would often be written using set analysis instead:
sum({< [OrderDate.autoCalendar.Year] = {2011} >} ] [Gross sales])
Which would ignore any selections made on the Year field and always apply 2011 instead.
Try
Sum(If([OrderDate.autoCalendar.Year] = Date(MakeDate(2011),'YYYY'), [Gross sales], 0)
The reason is that the "OrderDate.autoCalendar.Year" is really a date (Jan 1), but formatted as a Year...
Thank you for quick response. I forgot to write down that "Gross sales" is measure (sum=unitPrice*quantity).
There is still error:
Thank you for quick response. I forgot to write down that "Gross sales" is measure (sum=unitPrice*quantity).
There is still error:
You can't sum a sum, so unfortunately that won't work, regardless of the if() condition. You'll have to either use aggr() for the internal sum or re-write the formula to not use a nested aggregation.
Ok. Thank you for help! Have a nice day.