Seeking Advice on collating data

I have log file with three comma separated pieces of data.
A userid, a printer queue and a page count for that specific print job.
A userid appears multiple times, once for each print job.
A userid might print to different printers on different queues.

I’m spinning my wheels on trying to figure out how to collate the data. I’d like to have an end result that gives me a userid for each print queue and the total number of pages they sent to that print queue.

Example data

user1,PGP160,2
user2,INSTISS1,1
user2,INSTISS1,1
user1,PGP165,1
user3,PGP114,4
user4,PGP103,1
user4,PGP103,1

Getting the user, queue and pages printed is easy enough but I’m having trouble figuring a way to sort the user into a unique list, the print queue into a unique list and total the pages printed by the user to that queue while keeping the data collated.

Any suggestions on how I can approach this?

Edit - The data I’d like to have in the end would have the above appear as follows.

user1,PGP160,2
user1,PGP165,1
user2,INSTISS1,2
user3,PGP114,4
user4,PGP103,2

I didn’t get completely what you want and how you want to count but I’d try combining

and

Youy may show an example of what end result you would expect using the sample data you poasted.

Thanks @Olaf, you’re right. I’ll edit the question to include a result of what I’m trying to achieve. I’ll look at both of those, I hadn’t considered them.

If you like to solve it yourself you should not read any further … :wink: :grinning:

$inputData = 
@'
user1,PGP160,2
user2,INSTISS1,1
user2,INSTISS1,1
user1,PGP165,1
user3,PGP114,4
user4,PGP103,1
user4,PGP103,1
'@ | 
    ConvertFrom-Csv -Header User, PrintQueue, PageCount

$inputData | 
    Group-Object -Property User, PrintQueue |
        ForEach-Object {
            [PSCustomObject]@{
                User       = @($_.Group.User)[0]
                PrintQueue = @($_.Group.PrintQueue)[0]
                PageCount  = ($_.Group.PageCount | Measure-Object -Sum).Sum
            }
        } |
            Sort-Object -Property User, PrintQueue

… and the result would be this:

User  PrintQueue PageCount
----  ---------- ---------
user1 PGP160             2
user1 PGP165             1
user2 INSTISS1           2
user3 PGP114             4
user4 PGP103             2

Damn @Olaf , you make it look so easy. I just don’t have the experience with PS yet to make it that slick. Thanks. That produces exactly what I’m after.

:+1:t4: :slightly_smiling_face:

I’m glad it helped.

Can you verify/clarify this for me.

In the custom object you have this syntax.

User = @($_.Group.User)[0]

The $_.Group is an array from the group-object, right?

When I have code I try to understand it helps usually when I run it step by step and inspect the output …

$inputData | 
    Group-Object -Property User, PrintQueue 

Yes. It’s an array of hashtables.