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

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?
Multiple aggregates in SPARQL
SAP BO XI Desktop Intelligence Aggregate Calculations

Categories

HOME
qlikview
teradata
service
openacc
wifi
mysqli
abc
popover
highmaps
css-selectors
travis-ci-cli
kendo-asp.net-mvc
meson-build
python-3.4
scapy
virtualhost
rethinkdb
osx-yosemite
annyang
obd-ii
google-app-maker
theory
angular-universal
unreal-engine4
osclass
xmlhttprequest
derby
jinja2
responsive
web-testing
django-rest-auth
ampscript
git-branch
procedural-generation
oracle-golden-gate
ecmascript-2017
android-wear-2.0
suitescript
knapsack-problem
multiple-inheritance
angular2-changedetection
hierarchical-data
sqldependency
azure-table-storage
csproj
dynamics-ax-2012-r3
spring-data-gemfire
unity3d-5
favorites
rtos
n1ql
mootools
iterm2
motion
byobu
keychain
mixed-models
tapply
pexpect
libzip
python-venv
nshttpurlresponse
grails-2.0
gradlew
niagara-ax
ack
synchronized
qtwebkit
remap
nservicebus6
disassembly
tsc
turbolinks
mavlink
jigsaw
git-cherry-pick
gdi
pyshark
wizard
containstable
libgcrypt
musicbrainz
android-filterable
euro
android-networking
firebase-tools
mri
jsonmodel
jsonschema2pojo
nsurlrequest
xmlserializer
angular-file-upload
smartxls
mixradio
code-complete
misfire-instruction
friendly-url
junction-table
dnsbl
php-gettext
django-admin-tools
optimistic-concurrency
wxperl
facebook-winjs-sdk
inserthtml
jqzoom
virtual-printer
funambol
table-valued-parameters
web-search
pkcs#7
user-preferences
bootstrap-protocol

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