Using count in Doctrine2 - doctrine-orm

Count row by Doctrine
I have tables like this
id | name
---------
1 | john
2 | ken
3 | john
4 | ken
5 | ken
6 | haku
when I use this sentence
$em->createQuery("SELECT c.id FROM UserBundle:customer c group by c.name")->getResult()
I can get the pair of first id for each people.
1 | john
2 | ken
6 | haku
However ,I would like to get the count how many times each name appears, like below.
1 | john | 2
2 | ken | 3
6 | haku | 1
How can I make it?

For complicated queries, I'd probably use PDO directly, especially if you don't need to map to an entity.
Here is an example of how to use PDO directly:
$q = "your query here";
$stmt = $em->getConnection()->prepare($q);
$stmt->execute();
$results = $stmt->fetchAll(\PDO::FETCH_ASSOC);

Try this:
$em->createQuery("SELECT c.name, COUNT(c.id) as cnt FROM UserBundle:customer c group by c.name")->getResult();

Related

Single Filter for PowerBI

I have 2 tables in powerbi, one contains all transactions to and from people (each client identified with an id, where "I" can be either the receiver or sender of $) and the other is the detail for each client.
Table 1 would look something like
| $ | sender id | receiver id |
|---|-----------| ------------|
| 10| 1 | 2 |
| 15| 1 | 3 |
| 20| 1 | 2 |
| 15| 3 | 1 |
| 10| 3 | 1 |
| 25| 2 | 1 |
| 10| 1 | 2 |
The second table contains sender id and name:
| id | name |
|----|-------|
| 1 | "me" |
| 2 | John |
| 3 | Susan |
The expected result is something like (not necesarily in a table, just to show)
| $ sent | $ received | Balance|
|--------|------------|--------|
| 55 | 45 | +10 |
And in a filter have "John" and "Susan" so when i Select one of them i could see $ sent, $received and balance for each of them.
The problem of course is that i end up with one active and one inactive relationship so if i apply such a filter i end up with 0 in sender/receiver and the whole value in the other (depending which is made active and inactive) and if i make another table that's "id sender"+"name sender" then i cant filter all at once.
Is it possible to do this?
I hope this is kinda understandable
You will need to add 2 columns to your user table
received = CALCULATE(SUM(T1[$]), Filter(T1, UserTable[id] = T1[reveicer id]))
The same you can do for send. Now in your visual, use the new columns.
Enjoy!
after going around a bit I found a way to solve this, probably not the most orthodox way to do it, but it works.
What I did is to add 2 columns to my sales table, one was labeled "movement" and in sql it is just a 'case' where when the receiver is 'me' its "Charged" and when the receiver is 'not-me' its "Payment", then i added a column with a case so it would always bring me the 'not-me' id, and i used that for may relationship with my users table.
Then I just added filters in my cards making one a "Payment" card and the other a "Charged" card.
This is all following the previous example, it was actually just a bit more tricky as I could actually have a payment from me to myself, but thats just another "case" for when it was 'me-me'
Hope this is understandable, english is not my first language and the information i actually used is partially confidential so i had to make the above example.
thanks all and have a nice day.

Match if partial part of string exists in another column e.g. if AUD exists in one column highlight AUDUSD

Hopefully someone can help me with a google sheets formula to look up a currency in a column of currency pairs, I'm sure it's fairly basic but because it needs a partial match as the news will always be a single currency and the list of pairs will always be two currencies put together I am struggling to do this.
How my sheet is structured; I have a list of currency pairs in one column, the next column is what I'm trying to do. In the "news ?" column the value = "News" if the previous currency pair matches with any the values in H20 to H25. The value = "No News" if the currency pair does not contain any values in H20 to H25. In this example, these values are AUD and CAD as we have news on these currencies today to be wary of.
1 | Currency pairs | News ?
2 | AUDUSD | News
3 | EURUSD | No News
4 | GBPUSD | No News
5 | USDCAD | News
6 | USDCHF | No News
7 | USDJPY | No News
8 | AUDCAD | News
9 | AUDCHF | News
10 | AUDJPY | News
11 | AUDNZD | News
12 | AUDSGD | News
13 | CADCHF | News
14 | CADJPY | News
15 | CHFJPY | No News
etc...
And I have a column of currencies which has news occurring today e.g.
H19 | Today we have news on
H20 | AUD
H21 | CAD
H22 |
H23 |
H24 |
H25 |
My question is: How do I highlight via a formula if one part of the currency pair appears in the news column. Can be conditional formatting or a value in the next column as per the example which says "News" or "No News" (or 1 or 0, tick or cross, doesn't really matter as long as it flags if it matches with the news)
The tricky part is the currency pairs column will always be the six character pairs and the news column will always just be one single three-letter currency.
The news column will have anywhere between 0 news and say 5 rows of currencies which have news
I have tried things like this with no success so far:
=VLOOKUP(H20:H25&"*",A2,1,0)
=IF(REGEXMATCH(A2, H20:H25&"*"), 1, 0)
=if(COUNT(find(H20:H25,A2))=1,CHAR(10004))
formula in B2 cell:
=ARRAYFORMULA(IF(REGEXMATCH(A2:A15, TEXTJOIN("|", 1, A20:A25)), "News", "No News"))
custom conditional formatting formula:
=REGEXMATCH($A2, TEXTJOIN("|", 1, $A$20:$A$25))

How do I calculated group averages with a filter in DAX?

I've got data across 2 tables that kind of looks like:
Table 1
Mean | Activity | name_id
---------------------------
1 | Swimming | 1
3 | Basketball | 2
3 | Swimming | 3
9 | Running | 1
5 | Basketball | 3
TypeName | Name_id
------------------
ABC | 1
DEF | 2
GHI | 3
Assuming joins are in place, I want to run the equivalent of this SQL:
select activity, avg(mean)
from table1 a
inner join table2
on table1.name_id = table2.name_id
where table2.name_id = 'DEF'
I got a basic quick measure that does everything except for the filter for 'DEF' name_ids:
Average =
AVERAGEX(
KEEPFILTERS(VALUES('Table1'[Activity])),
CALCULATE(SUM('Table1'[Mean]))
)
I'm stumped as to where exactly I should put a filter. I also tried using CALCULATE as the base function, but was stumped on how to properly run that.

Power Bi create comma seperated list string where ids match

Im really new to Power Bi, I created the following table:
ID | POST_ID |
0 | 11 |
0 | 12 |
0 | 13 |
0 | 18 |
0 | 21 |
1 | 14 |
1 | 15 |
2 | 16 |
2 | 17 |
2 | 19 |
2 | 20 |
Now I need to pass this ids to an api as a comma seperated list, so I want to transform the table to:
ID | POST_ID |
0 | 11,12,13,18,21 |
1 | 14,15 |
2 | 16,17,19,20 |
But can't manage to do this. I assume it must be fairly easy to do? I have no clue to start, I've been messing around in the query editor now for a few hours and googling wont bring me much help either so far!
Thanks in advance!
Here is a solution
let
t=#table({"ID", "POST_ID"},{{0, 11},{0, 12},{0, 13},{0, 18},{0, 21},{1, 14},{1, 15},{2, 16},{2, 17},{2, 19},{2, 20}}),
group = Table.Group(t, {"ID"}, {{"val_list", each Text.Combine(List.Transform([POST_ID], Number.ToText), ",")}})
in
group
But... are you sure you finally need a text string?
If you pass result to API, perhaps you'd better pass a list of numbers
So your code should look like this
let
t=#table({"ID", "POST_ID"},{{0, 11},{0, 12},{0, 13},{0, 18},{0, 21},{1, 14},{1, 15},{2, 16},{2, 17},{2, 19},{2, 20}}),
group = Table.Group(t, {"ID"}, {{"val_list", each [POST_ID]}})
in
group

How can I match two columns of data by name?

I have two sets of data that look something like this:
Bill | 7
Sam | 13
Chuck | 9
and
Bill | 6
Sam | 3
Beth | 6
and I want:
Beth | 0 | 6
Bill | 7 | 6
Chuck| 9 | 0
Sam | 13 | 3
I don't even care if the data ends up looking like this:
Bill | 7 | Bill | 6
| | Beth | 6
Sam | 13 | Sam | 3
Chuck| 9 | Chuck| 0
I just would like to match up the names.
Your desired outcome - I've never seen such an order in "real life practice".
To use the data, I would go with an operating system tool to combine the source files
(like: copy file1 + file2 newfile.csv; new file extension for easily recognizing by OOo Calc).
In CALC you can then sort / filter, to show a persons data together, or sum / calculate with it.
If you want standard operations, like SUM per person, check out the pivot table feature.
HTH