aggregate-functions


'Your query does not include the specified expression as part of an aggregate function' error for calculated fields


I know this error is a recurrent topic in stackoverflow, but i haven't been able to find quite the solution on any of the questions i went through.
I am getting the good old aggregate function error, with which i am familiar with, on a SELECT query. The thing is that, in the query, there are 'Group by' fields, 'Sum' fields and 'Expression' fields, and apparently (after trying a bizillion versions of the same query) it is some of the fields falling in the latest category that are responsible for my headache.
The query is the following:
SELECT GRC.User, USU.displayName AS Nombre, USU.Colectivo AS Colectivo, USU.[Integra Responsable] AS [Integra Resp], USU.Responsable AS Responsable,
Sum(Ejecs_IDsGRC1.Ejecuciones) AS Funcion_1,
Sum(Ejecs_IDsGRC2.Ejecuciones) AS Funcion_2,
IIf(Count(Mats.[ID Usuario])>0,"Materializa",IIf([Funcion_1]>0,IIf([Funcion_2]>0,"N/A","Remediar2"),IIf([Funcion_2]>0,"Remediar1","Ambas"))) AS Accion,
IIf([Hist1].[Funcion] Is Not Null Or [Hist2].[Funcion] Is Not Null,"X",Null) AS RespuestaAnterior,
GRC.Risk, Riesgo_Funciones.FC1, Riesgo_Funciones.FC2, Riesgo_Funciones.Sistemas, Riesgo_Funciones.Concepto AS [Riesgo conceptual],
IIf([Funcion_1]>0,"Mantener","Remediar") AS Acc1,
IIf([Funcion_2]>0,"Mantener","Remediar") AS Acc2
FROM ((((((01_GRCres_UsusFunciones AS GRC LEFT JOIN USU_Maestro AS USU ON GRC.User = USU.[ID Usuario])
LEFT JOIN [04_EjecucionesPorFuncion_IDs GRC] AS Ejecs_IDsGRC1 ON (GRC.User = Ejecs_IDsGRC1.Usuario) AND (GRC.FC1 = Ejecs_IDsGRC1.Funcion))
LEFT JOIN [04_EjecucionesPorFuncion_IDs GRC] AS Ejecs_IDsGRC2 ON (GRC.User = Ejecs_IDsGRC2.Usuario) AND (GRC.FC2 = Ejecs_IDsGRC2.Funcion))
LEFT JOIN Riesgo_Funciones ON GRC.Risk = Riesgo_Funciones.Risk) LEFT JOIN [00_Total Materializaciones] AS Mats ON (GRC.Risk = Mats.Riesgo) AND (GRC.User = Mats.[ID Usuario]))
LEFT JOIN 00_Respuestas AS Hist1 ON (GRC.User = Hist1.[ID Usuario]) AND (GRC.FC1 = Hist1.Funcion))
LEFT JOIN 00_Respuestas AS Hist2 ON (GRC.User = Hist2.[ID Usuario]) AND (GRC.FC2 = Hist2.Funcion)
GROUP BY GRC.User, USU.displayName, USU.Colectivo, USU.[Integra Responsable], USU.Responsable, GRC.Risk, Riesgo_Funciones.FC1, Riesgo_Funciones.FC2, Riesgo_Funciones.Sistemas, Riesgo_Funciones.Concepto;
The 3 troublesome fields would be 'RespuestaAnterior', 'Acc1' and 'Acc2', although for the 3 of them (as well as for 'Accion' calculated field, which on its own works like a charm) i have marked 'Expression' as the aggregated total type of field.
What am i missing? I tried to add them to the GROUP BY statement as well (although i don't think that should be it) and it wouldn't work either.
Unfortunately, these tables contain client confidential data (besides there are a bunch of them) so i cant upload the data for testing... just if any of you guys sees something i'm no i would be deeply grateful!
Thanks a lot in advance.

Related Links

NHibernate - QueryOver criteria appearing in Where instead in Having clause, error
Howto aggregate on full data set in Spring Batch jobs?
Creating an aggregate function fails
Necessity of declaration of function in c and cpp
Calculate window average in tableau
Complexity asymptotic relation (theta, Big O, little o, Big Omega, little omega) between functions
What are TOP_COUNT and TOP_MAXCOUNT in BigQuery?
marklogic need advise for approach to aggregate documents
multiply(num) aggregate function in postgresql
Binding the Result of an Aggregate Function to a Projected Variable
tableau aggregate data based on dimension
where clause and aggregate functions
Is there such a thing as a join() aggregate function that concatentates field values at a specific character?
Aggregation of an expression in Django query spanning multiple tables
How to aggregate / roll up percentile measures
A peer-to-peer and privacy-aware data mining/aggregation algorithm: is it possible?

Categories

HOME
stanford-nlp
customization
gap-system
boxplot
watson-iot
cryengine
arguments
perl6
wavefront
vsixmanifest
revit-api
rename
adroitlogic
openscad
samba
geography
xforms
sonarlint
restructuredtext
klipfolio
angular2-pipe
opengraph
devexpress-mvc
bootstrap-accordion
ps
android-wear-2.0
grunt-contrib-uglify
large-files
angular-schema-form
dynamics-ax-2012-r3
paper-trail-gem
edirectory
jmsserializerbundle
mplab
urhosharp
log4net-configuration
spring-oauth2
wercker
contextmenustrip
microstrategy
dropdownbox
pyenv
dotnetnuke-module
server-side-swift
file-descriptor
quartz
datagridviewcombobox
paperclip
taleo
spring-webflow-2
gige-sdk
aot
multi-targeting
group
xcode7.1
jigsaw
bytearray
aws-kms
angular-i18n
window.location
pebble-js
sqlxml
jersey-test-framework
ewam
imageicon
random-sample
avrcp
jeet-grid
nexusdb
mri
sony-xperia
qxorm
launcher
os.walk
lwuit
zoneminder
disparity-mapping
yandex-api
smartxls
dayofweek
internet-radio
cvi
imaplib
mencoder
raddatepicker
kohana-orm
dd4t
pudb
boost.build
ncml
tasklist
expresso-store
waveout
states
systrace
erlide
bash4
motorola-droid
nsundomanager
apache-commons-email
parallel-python
soapexception
file-processing
cpack
norton
webdb
code-golf
dgml
mdd
rpxnow
script-tag
cstring

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App