Count Number of Rows with Condition - powershell

I have a document names.csv with two columns. I want to count the number of rows that have the same values and modify the document to display the count using Powershell. For example:
Joe Florida
Joe California
Joe Florida
Bob Texas
Joe Texas
Joe Florida
Joe Florida
Bob Minnesota
Joe California
I want the output to be:
Bob Minnesota 1
Bob Texas 1
Joe California 2
Joe Florida 4
Joe Texas 1
This needs to be generic because column 1 will contain an arbitrary number of names. I really do not know where to begin. Please only answer with full names (do not say gc for Get-Content).

You can use the Group-Object cmdlet here like below.
If csv is like below
Name,Place
Joe,Florida
Joe,California
Joe,Florida,
Bob,Texas
Joe,Texas
Joe,Florida
Joe,Florida
Bob,Minnesota
Joe,California
Import-Csv -Path C:\Temp\Temp.csv | Group-Object -Property Name,Place
You can put your own logic to write it to new csv.

Related

Spring data Mongo db sort based on substring

I have data like
John Willis Tampa, FL
Jane El Orlando, FL
Rick Manning Chicago, IL
Jason Woods Miami, FL
If a user searches for residents in Orlando, I would like to select all residents in Orlando and later append all residents living in Florida. So the result set should be like
Jane El Orlando FL
John Willis Tampa, Florida
Jason Woods Miami, FL
Last two records could be in any order but Orlando, FL should be first since user is searching for Orlando, FL
I can use the following criteria
criteria = Criteria.where("cityState").regex(", FL")
But how to sort is such that all the records with cityState = Orlando, FL will first.

Access 2010 Query across multiple fields

I am an absolute Noob when it comes to Access 2010. I am trying to figure out what I believe is a common task.
I want to do a Query across multiple fields giving me a total. Let me give you an example:
I sell fruit, only 3 kinds and say my Table has an ID, Name, Item 1, Item 2, Item 3, and other unrelated fields.
An order could look like this:
ID1 Bill Smith Apples
ID2 John Jones Bananas Apples
ID3 Mary Cross Oranges Bananas Apples
I would want a Query to "Scan" (probably the wrong word) the Item 1 field, Item 2 field, and Item 3 field and return a Totals count as follows:
Apples 3
Bananas 2
Oranges 1
Notice that Apples, Bananas and Oranges can be in ANY Field, in ANY order...
Thank you for your Time and Expertise
Ray
The problem is your table structure, how many items can be in each order, three, four, five? Do you intend to add another column if someone orders six items?
They way to do this is keep orders in one table and the line items in another and link them
Table orders:
order_id
name
1
Bill Smith
2
John Jones
3
Mary Cross
Table orderItems:
item_id
order_id
item
1
1
Apples
2
2
Bananas
3
2
Apples
4
3
Bananas
5
3
Apples
6
3
Oranges
Then use a query which joins the two tables together:
select o.order_id,o.name,oi.item from orders o left join orderItems oi on o.order_id = oi.order_id
Will give an output of:
Order_ID
Name
Item
1
Bill Smith
Apples
2
John Jones
Apples
2
John Jones
Bananas
3
Mary Cross
Apples
3
Mary Cross
Bananas
3
Mary Cross
Oranges

Tableau Calculation with a Filter in place

I'm trying to get the count of calls received by an individuals, both initial answer and any possible transferred over by another person.
My workbook has a filter based on the individual who first answers the phone. Now I need to add in any calls that were transferred over. These calls are usually answered by another individual.
This is what I would like to see
John: #calls =3 | #calls Transferred to =1
Where the data would show this:
Incoming | Transferred to
John | James
John | NUll
John | NUll
James | John
Does anybody have a way to get in the last call to be attribute it to John with the filter in place?
My filter of John would give me the three calls, but would remove the transferred call.
Try creating two calculated fields using the following formulas and then use them as filters.
Filter - John
if contains([Incoming], "John") then "John"
ELSEif
CONTAINS([Transferred to], "John") then "John"
END
Filter - James
if contains([Incoming], "James") then "James"
ELSEif
CONTAINS([Transferred to], "James") then "James"
END

Sphins Regexp maps to only single words

I am trying to map regexp so when a user enters a specific word I force them to choose a specific other term in the table.
For instance I have as simple example fields:
Bob
Bob Smith
Bob Jones
Sally
Sally Smith
Sally Jones
If I do
regexp_filter=Bob>Bob Smith to make sure when a user simply enters Bob I push Bob Smith instead and then do a sphinql search:
Select * from Index where MATCH('Bob')
I still get all the Bob records (in other words it did not interpret as Bob Smith
However if I dod
regexp_filter=Bob=>Sally
Then Select * from Index where MATCH('Bob') returns all the Sally records.
I am "simply" trying to force the index to return the Bob Jones record should a user simply search on Bob.
FYI I did try
Select * from Index where MATCH('^Bob$')
and that returned NULL
I still get all the Bob records (in other words it did not interpret as Bob Smith
Because the regex is applied to BOTH the query text and document text during indexing. So becomes MATCH('Bob Smith'), but your documents also become
Bob Smith
Bob Smith Smith
Bob Smith Jones
... so your query, matches all three documents, same if didnt have the regex!
I am "simply" trying to force the index to return the Bob Jones record should a user simply search on Bob.
Wonder if you meaning should NOT return ?
... in which case can use MATCH('^Bob$') but rememeber to remove the regex. Or could perhaps use MATCH('"^Bob$"') an extra set of quotes to use phrase mode.
Try also MATCH('^Bob$ ') with a space! some versions of sphinx has a bug unless a space after the $!

Crystal Reports Rows in Group

I have a report grouped by Supplier. In the details section for this group, there are customer names with other fields of information. The problem is that a customer may be listed several times, but I only want one record to show per customer.
Supplier
John Doe 10/15 $25.00 Eggs
John Doe 10/15 $29.00 Milk
Susan Weva 10/12 $15.00 Corn
Susan Weva 10/18 $11.00 Bread
What I want is one complete row for John Doe and one for Susan Weva. Any idea as to how I can do this? I tried to suppress each field, but that did not seem to work.
There is one way (which i use in this situations) and it work.
So your data looks like this
John Doe 10/15 $25.00 Eggs
John Doe 10/15 $29.00 Milk
Susan Weva 10/12 $15.00 Corn
Susan Weva 10/18 $11.00 Bread
From what i have understand you want to have your output like
John Doe some columns
Susan Weva some columns
To show it only once per group put fields in group header or group footer. In your case all other columns are different and you should "summarize" those fields. For field price is easy, just do summarize by group and you have for each person amount. But dates and last columns makes a problem. So you should learn about using Cross-tab to solve this problem. If you need only sum of price, then put fields in group header or group footer and it will be show only once per group.
Hope it helps