Counting specific numbers in textbox of two or more rows , (no duplicates) (3 Viewers)

Aminam64

New member
Local time
Today, 19:15
Joined
Feb 14, 2025
Messages
4
I have a table with many rows , in order of counting the numbers in rows need a query to do that
A. B. C. D. E. F.
X. Y. 1. 3. 1. 3
X. Z. 4. 5. 4. 5
X. W. 6. 4. 6. 4
X. U. 5. 6. 5. 6
X. N. 2. 3. 2. 3
X. Have a 5 sub and 6 specific numbers
X. 5. 6
I wish u guys get the idea
 
Hi. Welcome to AWF!

Perhaps you can attach an Excel file with sample data and the results you want?
 
Here a sample in excel template , tnk u
 
Are you trying to;
1) Return the COUNT of rows where there is a number in a specific column?
2) Return the COUNT of rows where there is a number in any column?
3) Return the number of columns per row that have numbers then total this number?
 
Are you trying to;
1) Return the COUNT of rows where there is a number in a specific column?
2) Return the COUNT of rows where there is a number in any column?
3) Return the number of columns per row that have numbers then total this number?
Numbers are duplicate in separate rows , I want to count one time for each number , as you see there is few number 3 or number 5 in each columns , I want to count just one time for each number
 
This data is in table in Access? You provide 5 rows of sample data but say "4 rows" in statement.

You want to know how many distinct numbers are in all 5 records combined - which in this case is 6 numbers - all from the WelderX columns?

Your options are a VBA procedure or a sequence of queries, which can be nested.

Consider:

SELECT Q.*, (SELECT Count(*) FROM Data WHERE [lone no]=Q.[lone no]) AS CntRecs FROM
(SELECT [lone no], Count(*) AS CntNums FROM (
SELECT [lone no], welder1 AS welder FROM Joints
UNION SELECT [lone no], welder2 FROM Joints
UNION SELECT [lone no], welder3 FROM Joints
UNION SELECT [lone no], welder4 FROM Joints) AS Q
GROUP BY [lone no]) AS Q;

The output is

lone noCntNumsCntRecs
swf65




 
Last edited:
on my case, i uses VBA and call it from the query:
the vba:
Code:
Public Function fncCountDistinct(ByVal LoneNo As String, FieldName As String) As Integer
    Static db As DAO.Database
    Dim SQL As String
    If db Is Nothing Then
        Set db = CurrentDb
    End If
    SQL = "SELECT DISTINCT [" & FieldName & "] FROM weld WHERE [lone no]='" & LoneNo & "';"
    With db.OpenRecordset(SQL, dbOpenSnapshot, dbReadOnly)
        If Not (.BOF And .EOF) Then
            .MoveLast
            fncCountDistinct=.RecordCount
        End If
        .Close
    End With
End Function

Query1:
Code:
SELECT weld.[lone no],
fncCountDistinct([lone no],"joint") AS JointsCount,
fncCountDistinct([lone no],"Welder1") AS Welder1JointsCount,
fncCountDistinct([lone no],"Welder2") AS Welder2JointsCount,
fncCountDistinct([lone no],"Welder3") AS Welder3JointsCount,
fncCountDistinct([lone no],"Welder4") AS Welder4JointsCount
FROM weld
GROUP BY weld.[lone no], fncCountDistinct([lone no],"joint"), fncCountDistinct([lone no],"Welder1"), fncCountDistinct([lone no],"Welder2"), fncCountDistinct([lone no],"Welder3"), fncCountDistinct([lone no],"Welder4");


lone noJointsCountWelder1JointsCountWelder2JointsCountWelder3JointsCountWelder4JointsCount
swf55454


you also need to normalize your data when you use Ms Access:

LoneNo-------------Entity--------------------JointNo
swf------------------joint---------------------1
swf------------------joint---------------------2
swf------------------joint---------------------3
swf------------------joint---------------------4
swf------------------joint---------------------5
swf------------------welder1-----------------1
swf------------------welder1-----------------2
swf------------------welder1-----------------4
swf------------------welder1-----------------6
swf------------------welder1-----------------3

etc...
 
Last edited:
I am thinking normalized is like:

IDlone nojointwelderdata
1swf111
2swf122
3swf131
4swf141
5swf212
6swf223
7swf232
8swf242
9swf314
10swf325
11swf334
12swf344
13swf416
14swf424
15swf436
16swf446
17swf513
18swf522
19swf533
20swf543










 
I wish u guys get the idea
I wish we did, too! You'll need to put a lot more effort into explaining your problem if you expect help from others.
You get out what you put in, which in this case was next to nothing.
 
Numbers are duplicate in separate rows , I want to count one time for each number , as you see there is few number 3 or number 5 in each columns , I want to count just one time for each number
One number per record, or all records?
 

Users who are viewing this thread

Back
Top Bottom