Count number and multiply with field value (1 Viewer)

FoolzRailer

New member
Local time
Today, 11:40
Joined
Apr 15, 2016
Messages
25
Hello

I'm trying to do a Total query, that is calculating the cost of building certain systems. Right now I'm just trying to count the number of Nodes and multiply that with field UnitPrice, to find out how must the cost of nodes is based on their size (the sum of all the money spent on 1 meter nodes fx.).

However I keep getting an aggregate function error.

Tried to translate my query language. Don't mind the locale settings for ";" or ",":
Format(Sum([Nodes_UP].[UnitPrice]*Count([NodesList].[Nodes]));"Currency")

What am I doing wrong here? Full Code below.

SQL:
SELECT Nodes_UP.ID, Nodes_UP.Description, Nodes_UP.UnitPrice, "Stk." AS UnitType, Count(NodesList.Nodes) AS Quantities, Format(Sum([Nodes_UP].[UnitPrice]*Count([NodesList].[Nodes])),"Currency") AS Total

FROM List_Nodes INNER JOIN Nodes_UP ON List_Nodes.JoinNodes = Nodes_UP.Join

GROUP BY Nodes_UP.ID, Nodes_UP.Description, Nodes_UP.UnitPrice, "Stk."

ORDER BY Nodes_UP.ID;
 

June7

AWF VIP
Local time
Today, 01:40
Joined
Mar 9, 2014
Messages
5,472
I think you will have to do a separate query that counts the nodes and JOIN that query to Nodes_UP. You could do it as a nested subquery.

Might be a way to day this in report with Sorting & Grouping and aggregate calcs.

If you want to provide db for analysis, follow instructions at bottom of my post.
 

Eugene-LS

Registered User.
Local time
Today, 12:40
Joined
Dec 7, 2018
Messages
481
What am I doing wrong here?
try replacing the line:
SQL:
... , Format(Sum([Nodes_UP].[UnitPrice]*Count([NodesList].[Nodes])),"Currency") AS Total ...
to
SQL:
... , Format(Count([UnitPrice])*Sum([Nodes]),"Currency") AS Total ...
You have a round bracket in the wrong place.
 

ebs17

Well-known member
Local time
Today, 11:40
Joined
Feb 7, 2020
Messages
1,946
I have shortened the content of the line in question (format, superfluous brackets):
Code:
SUM(Nodes_UP.UnitPrice * COUNT(NodesList.Nodes)) AS Total
It looks like you wanted to do two consecutive aggregations in one step:
Count, multiply number by price, sum the whole.
This is not possible. As @June7 says, such steps must take place in their own query levels.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:40
Joined
Feb 19, 2002
Messages
43,275
formatting a field this way turns it into a string. do NOT format data you want to do arithmetic with in queries. Format in the report or form using the format property and NOT the format function.
 

Users who are viewing this thread

Top Bottom