Please help with MS Access

bcmind

Senior member
Oct 9, 1999
539
0
0
I have a Table:

Class Rep Sales Cost
AC 10 $5 $2
AC 39 $5 $2
AC 10 $6 $3
AC 39 $10 $3
QS 10 $2 $1
QS 39 $2 $1
QS 39 $2 $1
QS 10 $3 $2


I want this result:

Class Rep Total Sales Total Cost Profit Margin
AC 10 $11 $5 120%
AC 39 $15 $5 200%
QS 10 $5 $3 66.67%
QS 39 $4 $2 100%

Please teach me how to do this... TIA!!!
 

LeiZaK

Diamond Member
May 25, 2005
3,749
4
0
In "SQL View" for a new query, enter the following:

SELECT [tablename].Class, [tablename].Rep, Sum([tablename]![Sales) AS [Total Sales], Sum([tablename]![Cost]) AS [Total Cost], Round((([Total Sales]-(IIf([Total Cost] Is Null,0,[Total Costl])))/[Total Sales]*100),2) AS [Profit Margin]
FROM [tablename]
GROUP BY [tablename].Class, [tablename].Rep;

I think that will do it...

Also make sure that in the "design view" your Sum and Round fields are set to "Expression" and the others are set to "Group By"
 

bcmind

Senior member
Oct 9, 1999
539
0
0
LdiZak,

Thank you for your reply... and it works great... but now on the the next step...

I want this result:

Rep Total Sales Total Cost
10 $16 $8
39 $19 $7

Total Sales is coming from AC + QS (Total Sales)
Total Cost is coming from AC + QS (Total Cost)

TIA!!!!
 

LeiZaK

Diamond Member
May 25, 2005
3,749
4
0
Originally posted by: bcmind
LdiZak,

Thank you for your reply... and it works great... but now on the the next step...

I want this result:

Rep Total Sales Total Cost
10 $16 $8
39 $19 $7

Total Sales is coming from AC + QS (Total Sales)
Total Cost is coming from AC + QS (Total Cost)

TIA!!!!

Sure.

SELECT [tablename].Rep, Sum([tablename]![Sales) AS [Total Sales], Sum([tablename]![Cost]) AS [Total Cost]
FROM [tablename]
GROUP BY [tablename].Rep
 

bcmind

Senior member
Oct 9, 1999
539
0
0
Originally posted by: LeiZaK
Originally posted by: bcmind
LdiZak,

Thank you for your reply... and it works great... but now on the the next step...

I want this result:

Rep Total Sales Total Cost
10 $16 $8
39 $19 $7

Total Sales is coming from AC + QS (Total Sales)
Total Cost is coming from AC + QS (Total Cost)

TIA!!!!

Sure.

SELECT [tablename].Rep, Sum([tablename]![Sales) AS [Total Sales], Sum([tablename]![Cost]) AS [Total Cost]
FROM [tablename]
GROUP BY [tablename].Rep


You are the best!
 

bcmind

Senior member
Oct 9, 1999
539
0
0
Originally posted by: beggerking
use Format( your calculation, "Percent")
to show percentages.

I'm sorry... i'm kinda new to this... can you explain it in more detail?
 

LeiZaK

Diamond Member
May 25, 2005
3,749
4
0
Originally posted by: bcmind
Originally posted by: LeiZaK
Originally posted by: bcmind
LdiZak,

Thank you for your reply... and it works great... but now on the the next step...

I want this result:

Rep Total Sales Total Cost
10 $16 $8
39 $19 $7

Total Sales is coming from AC + QS (Total Sales)
Total Cost is coming from AC + QS (Total Cost)

TIA!!!!

Sure.

SELECT [tablename].Rep, Sum([tablename]![Sales) AS [Total Sales], Sum([tablename]![Cost]) AS [Total Cost]
FROM [tablename]
GROUP BY [tablename].Rep


You are the best!

 

LeiZaK

Diamond Member
May 25, 2005
3,749
4
0
Originally posted by: bcmind
Originally posted by: beggerking
use Format( your calculation, "Percent")
to show percentages.

I'm sorry... i'm kinda new to this... can you explain it in more detail?

SELECT [tablename].Class, [tablename].Rep, Sum([tablename]![Sales) AS [Total Sales], Sum([tablename]![Cost]) AS [Total Cost], Format((([Total Sales]-(IIf([Total Cost] Is Null,0,[Total Costl])))/[Total Sales]*100),"0.00%") AS [Profit Margin]
FROM [tablename]
GROUP BY [tablename].Class, [tablename].Rep;

Look where I updated the Profit margin section... I think that's how it works.
 

beggerking

Golden Member
Jan 15, 2006
1,703
0
0
Great job!!

I think the only thing is.. you need to actually type out "Percent" .. its a function constant..
 

bcmind

Senior member
Oct 9, 1999
539
0
0
OK.... problem with synthax....

SELECT PCSLS.Class, PCSLS.RepNum, Sum(PCSLS.[Sales Amount]) AS [SumOfSales Amount], Sum(PCSLS.[Cost Amount]) AS [SumOfCost Amount], PCSLS.Profit, Format((([SUMOFSALES AMOUNT]-(lf(([SUMOFCOST AMOUNT] is null, 0, [SUMOFCOST AMOUNT])))/[SUMOFSALES AMOUNT]^100, "0.00%") AS [PROFIT MARGIN]

please help!
 

LeiZaK

Diamond Member
May 25, 2005
3,749
4
0
Originally posted by: bcmind
OK.... problem with synthax....

SELECT PCSLS.Class, PCSLS.RepNum, Sum(PCSLS.[Sales Amount]) AS [SumOfSales Amount], Sum(PCSLS.[Cost Amount]) AS [SumOfCost Amount], PCSLS.Profit, Format((([SUMOFSALES AMOUNT]-(lf(([SUMOFCOST AMOUNT] is null, 0, [SUMOFCOST AMOUNT])))/[SUMOFSALES AMOUNT]^100, "0.00%") AS [PROFIT MARGIN]

please help!

Try the word "Percent" in place of the "0.00%" as beggarking mentioned and see if that works...
 

bcmind

Senior member
Oct 9, 1999
539
0
0
Format((([SUMOFSALES AMOUNT]-(lf(([SUMOFCOST AMOUNT] is null, 0, [SUMOFCOST AMOUNT])))/[SUMOFSALES AMOUNT]^100, "PERCENT") AS [PROFIT MARGIN]

no go

 

LeiZaK

Diamond Member
May 25, 2005
3,749
4
0
Originally posted by: bcmind
Format((([SUMOFSALES AMOUNT]-(lf(([SUMOFCOST AMOUNT] is null, 0, [SUMOFCOST AMOUNT])))/[SUMOFSALES AMOUNT]^100, "PERCENT") AS [PROFIT MARGIN]

no go

Can you do without the percent sign?
 

beggerking

Golden Member
Jan 15, 2006
1,703
0
0
Originally posted by: bcmind
Format((([SUMOFSALES AMOUNT]-(lf(([SUMOFCOST AMOUNT] is null, 0, [SUMOFCOST AMOUNT])))/[SUMOFSALES AMOUNT]^100, "PERCENT") AS [PROFIT MARGIN]

no go

try delete ^100 out...
 

KLin

Lifer
Feb 29, 2000
30,127
501
126
Originally posted by: bcmind
Format((([SUMOFSALES AMOUNT]-(lf(([SUMOFCOST AMOUNT] is null, 0, [SUMOFCOST AMOUNT])))/[SUMOFSALES AMOUNT]^100, "PERCENT") AS [PROFIT MARGIN]

no go

Use formatpercent() instead of format().

FormatPercent([SUMOFSALES AMOUNT]-iif(IsNull([SUMOFCOST AMOUNT]), 0, [SUMOFCOST AMOUNT]/[SUMOFSALES AMOUNT])) AS [PROFIT MARGIN]

EDIT: it would be better not to include spaces in field names (ie, instead of [PROFIT MARGIN] you should use ProfitMargin, etc.)
 

LeiZaK

Diamond Member
May 25, 2005
3,749
4
0
Originally posted by: KLin
Originally posted by: bcmind
Format((([SUMOFSALES AMOUNT]-(lf(([SUMOFCOST AMOUNT] is null, 0, [SUMOFCOST AMOUNT])))/[SUMOFSALES AMOUNT]^100, "PERCENT") AS [PROFIT MARGIN]

no go

Use formatpercent() instead of format().

FormatPercent([SUMOFSALES AMOUNT]-iif(IsNull([SUMOFCOST AMOUNT]), 0, [SUMOFCOST AMOUNT]/[SUMOFSALES AMOUNT])) AS [PROFIT MARGIN]

EDIT: it would be better not to include spaces in field names (ie, instead of [PROFIT MARGIN] you should use ProfitMargin, etc.)

I know that... and you know that, but don't go pushing your nomenclature around here.

 

bcmind

Senior member
Oct 9, 1999
539
0
0
Originally posted by: beggerking
Originally posted by: bcmind
Format((([SUMOFSALES AMOUNT]-(lf(([SUMOFCOST AMOUNT] is null, 0, [SUMOFCOST AMOUNT])))/[SUMOFSALES AMOUNT]^100, "PERCENT") AS [PROFIT MARGIN]

no go

try delete ^100 out...

Format((([SUMOFSALES AMOUNT]-(lf(([SUMOFCOST AMOUNT] is null, 0, [SUMOFCOST AMOUNT])))/[SUMOFSALES AMOUNT], "PERCENT") AS [PROFIT MARGIN]

no go
 

bcmind

Senior member
Oct 9, 1999
539
0
0
Originally posted by: KLin
Originally posted by: bcmind
Format((([SUMOFSALES AMOUNT]-(lf(([SUMOFCOST AMOUNT] is null, 0, [SUMOFCOST AMOUNT])))/[SUMOFSALES AMOUNT]^100, "PERCENT") AS [PROFIT MARGIN]

no go

Use formatpercent() instead of format().

FormatPercent([SUMOFSALES AMOUNT]-iif(IsNull([SUMOFCOST AMOUNT]), 0, [SUMOFCOST AMOUNT]/[SUMOFSALES AMOUNT])) AS [PROFIT MARGIN]

EDIT: it would be better not to include spaces in field names (ie, instead of [PROFIT MARGIN] you should use ProfitMargin, etc.)


no go
 

bcmind

Senior member
Oct 9, 1999
539
0
0
Originally posted by: 6000SUX
I'm surprised no one remarked on the lack of a primary key.

everything is on the same table... no other table is involved... do I still need a Primary Key?
 

bcmind

Senior member
Oct 9, 1999
539
0
0
just to refresh everyone's mind... this works w/o calculating the "Percent"

I just need the Percent to work..

SELECT LauraAllClassAMT1.RepNum, Sum(LauraAllClassAMT1![SumOfSales Amount]) AS [TOTAL SALES Amount], Sum(LauraAllClassAMT1![SumOfCost Amount]) AS [TOTAL COST], Sum(LauraAllClassAMT1!Profit) AS PROFIT
FROM LauraAllClassAMT1
GROUP BY LauraAllClassAMT1.RepNum;

 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |