Libreoffice count with condition and grouping - spreadsheet

I need to count the number of non empty cells in column Foo grouped by column Subject (Using LibreOffice)
Subject Foo
subject_1 20
subject_1
subject_1 2
subject_2 4
subject_2
subject_3
So basically my output need to be:
subject_1 2
subject_2 1
subject_3 0
countA does the job of counting non empty cells, but cannot group.
I tried countif, but I doesn't accept the conditions I put on it.
How can I do a count given a condition (empty cell in my case) and grouping (by the value of another column)
Thanks

With your countif, what params did you try?
using len(cell)<>0 should do the trick.

Ok, found a way to do it.
Supposing you have your data in the columns A,B and the unique list of subjects in the column D, the following formula does the job.
=COUNTIFS($B$2:$B$4000,"<>",$A$2:$A$4000, D2)
Basically it's a count with two conditions which both need to be true.
The first condition checks if the Bi cell is not empty, the second checks if the Ai cell corresponds to the subject in the Di cell (which is the unique subject)
This formula can be set in cell E2 and slide it down, so the last part D2 will point to the corresponding subject in Di.

Related

Listing the top value of rows based on a certain value in google spreadsheets

I have the following excel DPS table(s) all listed below eachother:
Column A Column B Column C
Parse Name DPS
61 Arlisk 991.7
46 Tritla 913.9
Parse Name DPS
79 Arlisk 1156.3
87 Lucija 1090.8
I have another name-table, which simply lists the names Arlisk, Tritla and Lucija.
Now I want to add another column to the name-table that shows the highest value found in column D of the other table of all rows that refer to the name of that row.
In other words the new table should list each name's highest DPS found across all the other tables.
I found the following, but the formula is wrong and Im not familiara enough with it to fix it further.
=ArrayFormula(MAX(IFERROR(INDEX($C$4:$C$999 ,SMALL(IF($B$4:$B$999=$B$4 ,ROW($B$4:$B$999)-ROW($B$4)+1),ROWS($B$4:$B4))),"")))
Could anyone give me some advice on the solution?
You want to get max DPS per name across all tables?
Given that those tables are in the same columns, then FILTER and MAX can give you the max DPS per name.
Formula:
=max(filter(C:C, B:B=E2))
Output:
You could also use the formula below to create a separate table. This will automatically list the unique names together with the max DPS based on the tables available in the range.
=query({B2:C}, "select Col1, max(Col2) where Col1 is not null and Col2 is not null group by Col1")
Output:

highlight row if cell value doesn't match with another row Power BI

I have 2 columns in a PowerBI table which I would like to compare and highlight if the value doesn't match.
Example -
ID Column1 Column2
1 AA AA
2 BB BBA
3 DD DD
4 EE E
In the output, I would like to highlight the column 1 cell or the entire row if the value is not an exact match with column 2.
I have search a lot for the solution and strangely I haven't found any solution.
Can someone help me to solve the problem!
This is my solution:
First create an auxiliar column with a simple logic to detect wich rows are different.
NoMatch = IF( Tabl3[Column1] = Tabl3[Column2], 1, 0 )
Then select your visualization and go to Format --> Conditional Format.
Select the ID column, activate the background color option and select advanced options.
Go to rules and select the column NoMatch then you have to create 2 rules as the followings (My pbi version is on spanish but you will get the idea)
Repeat this process for every column you are interested.
This is the result
Hope it helps you.

Comparing two columns in Business Objects

I need to compare two columns from two queries and put the result into a 3rd column.
Column 1 is the master sheet (Query 1) where the main ID number list is.
Column 2 on another Query (Query 2) are the ID numbers I want to compare to column 1 and return a "Yes" result in column 3 if the same ID is present on Column 2 (Query 2) without removing the rows where there are no results.
I can manage to get the report to filter column one to match the list on column 2 using the following simple formula.
=if[dimension1]=[dimesnion2]Then "Yes" else " "
I need all the data to remain unfiltered on Query 1 and just a Yes or a blank in column 3.
Thanks

How to select the closest matching row of values from a table using c#?

Suppose I have a table(3 rows x 4 columns).
Consider a database table where the first three rows are inputs. If the fourth row is added as a input to the table, the algorithm should match the incoming "A" input with previous all "A" inputs in the table and find the nearest match and it should do the same for B, C and D also. And finally it should select the appropriate row which has a closest match with the input and it should be selected. In this case the first row has closest match with the incoming fourth row and hence it should be selected.
P.S : SQL can also be used to achieve this.
Something on the line of:
select *, abs(A-newA) from table group by A
having abs(A-newA)=min(abs(A-newA))
;
// etc..
where newA, ... are to be substituted (prepared statement with value binding) with the new entry coordinates
select * from table where (abs(A-newA)+abs(B-newB)+...)=
(select min((abs(A-newA)+abs(B-newB)+...) from table)
;

SQL index match to find duplicate data

I have the following table
Code Name Task
aa jones DC
ab dave DC
aca james IF
aca james DC
ab trevor IF
aa jones IF
ag francis DC
ag francis IF
af derek SF
af derek DC
This is a very big table, above is just a quick example.
So, I would like some help finding the code and name that have completed a IF or SF task and a DC task.
I would like it to show where one person has touched both of these tasks. The hierarchy of the tasks is; it comes in as either a SF or IF then someone will do that, then off the back of that we receive a DC task, and I want the ones where it has been completed by the same person, with the same reference number.
I am able to do this in excel with an INDEX MATCH function, but this takes up a tremendous amount of calculation time due to the size of the table.
One way to approach this is using group by with a having. This is a flexible way of expressing these types of conditions:
select code, name
from table t
group by code, name
having sum(case when task = 'DC' then 1 else 0 end) > 0 and
sum(case when task in ('IF', 'SF') then 1 else 0 end) > 0;
Each condition in the having clause counts the number of rows that meet the particular condition. The first, for instance, counts the rows that match 'DC' and takes only the code, name pairs that have at least one such match.
SELECT code,name FROM YOUR_TABLE_NAME WHERE task = 'DC' AND (task = 'IF' OR task = 'SF') GROUP BY name
try this query
Gordon Linoff's query can be made easier under the hypothesys that IF and SF are synonym and cannot be both present for the same Code-Name couple, as the data provided by the OP suggests
SELECT code, name
FROM table t
GROUP BY code, name
HAVING SUM(CASE WHEN task IN ('IF', 'SF', 'DC') THEN 1 ELSE 0 END) = 2;
select code,name from (select distinct code,name from table1 where task='SF' or task='IF') as temp1 inner join (select distinct code as code2,name as name2 from table1 where task='DC') as temp2 on code=code2,name=name2;
I'm assuming that you have the table in table1. The code constructs two tables temp1 and temp2. temp1 contains those codes and names which have been assigned SF and IF. temp2 contains those codes and names which have been assigned DC. Finally, I join the two tables together to find code-name pairs in both tables. This is faster than in Excel because the database engine probably temporarily indexes the columns being joined on.
Actually, you can do this in Excel. You sort the table by code and name, then enter the following formulas (assuming "Code" is in A1):
D2=if(and(A2=A1,B2=B1,D1),true,or(C2="IF",C2="SF"))
E2=if(and(A2=A1,B2=B1,E1),true,C2="DC")
Select these two cells, and double-click the fill-handle (the little square at the bottom right of the selection). Then, with the two columns selected, copy, and then "Paste Special..." > "Values". Then, filter (Alt-D-F-F) for the rows with values in columns D and E being both true. That is the result you want. Select these rows and copy to a new sheet if desired.
Alternatively, you can follow the SQL "group by" solution given by Gordon, so that you do not need to sort: Create two new columns like the above, but:
D1: "D"
E1: "E"
D2=if(or(C2="IF",C2="SF"),1,0)
E2=if(C2="DC",1,0)
Then, "Insert" > "PivotTable", drag "Code" and "Name" to be row labels. Drag "D" to be under Values, click on it, "Value Field Settings...", and then select "Max". Do the same for "E", and then the rows with 1 in both D and E will be the result you want.