google sheet - propagate a MAXIF function whitin a column - google-sheets

I have a table in a first sheet called 'Ansewers to form' with :
Date
Name
First_Name
18/01/2023 14:44:18
Name1
FName1
18/01/2023 14:46:24
Name1
FName1
18/01/2023 16:37:30
Name2
FName2
18/01/2023 16:47:12
Name1
FName1
18/01/2023 16:47:35
Name3
FName3
And a second table called 'sheet1':
Date
Name
First_Name
18/01/2023 16:47:12
Name1
FName1
_
Name2
FName2
_
Name3
Fname3
I would like to recover the latest connection of each Name/Fname.
So I the cell A2 of sheet1 I have this formula :
=MAXIFS('Answers to form'!A2:A;'Answers to form'!B2:B;B2;'Answers to form'!C2:C;C2)
I would like to propagate the formula (just like with arrayformula); meaning that in A3 you have
=MAXIFS('Answers to form'!A2:A;'Answers to form'!B2:B;B3;'Answers to form'!C2:C;C3), and so...
Any idea ?

In Google Sheets you might lock a column or row with $.
In your case
=MAXIFS('Answers to form'!$A$2:$A;'Answers to form'!$B$2:$B;$B2;'Answers to form'!$C$2:$C;$C2)
Will drag on second line (which is line 3) to
=MAXIFS('Answers to form'!$A$2:$A;'Answers to form'!$B$2:$B;$B3;'Answers to form'!$C$2:$C;$C3)

Related

QUERY in ARRAYFORMULA to FILTER, JOIN and LEN

Given a table like this one:
A
B
C
D
E
1
Tese
(2021/039-07964)
(8146.000336/2021-60)
Tema 1092
2
Afetado
Tema 1092
Controvérsia 251
|3|Tese|(2021/0390796-6)||Tema 1093|Controvérsia 258|
|4|Afetado|||Tema 1093|Controvérsia 258|
|5|Tese|(2021/0390796-7)|(8146.000338/2021-50)||Controvérsia 238|
As long strings in Col A's rows are equal to "Tese", Col F should return a string (with line breaks) that compiles Col B to D strings that are not null in the same row.
So, row 1 of Col F should be:
F
(2021/0390796-4)(8146.000336/2021-60)Tema 1092
Row 2 of Col F should be:
F
(2021/039-07966)Tema 1093Controvérsia 258
And so on
I'm using a dropdown formula to do the job, which is working fine:
=IFERROR(IF(A1="Tese",JOIN(CHAR(10),FILTER(B1:E1, LEN(B1:E1))),""))
But it would be easier if it could be replaced by an array formula (the table is over 4,000 rows!).
I think it is possible to use a query, but I could not write the formula down.
The real table is here: link
Clear all contents of column G and try in G1
={"Informações completa da tese"; INDEX(IF(A2:A="Tese"; SUBSTITUTE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(SUBSTITUTE(B2:F; " "; "$"));;ROWS(A2:A)))); " "; char(10)); "$"; " ");))}
See if that helps?

Google sheets Array split function formula

I have this Google sheet:
I am using this formula to split my strings in columns
=ARRAYFORMULA(IFERROR(IF(D2:D=1, SPLIT(A2:A, "+"), SPLIT(C2:C, "+"))))
Molecules ID NAME Vitamin_in_name NAME1 NAME2 NAME3
VITAMIN B1 + VITAMIN B6 + VITAMIN B12 1 VITAMIN B1,B6,B12 1 VITAMIN B1 VITAMIN B6 VITAMIN B12
2 LIDOCAINE + VITAMIN B4,B8,B10 1
3 SALICYLIC ACID + TALC 0 SALICYLIC ACID TALC
I would like to return this sheet. IF the word "vitamin_in_name" = 1 and "molecules" row is empty to re-format the data like in ID2 Column name1, name2, name3. how can i do modify my array formula to do that?
Molecules ID NAME Vitamin_in_name NAME1 NAME2 NAME3 NAME4
VITAMIN B1 + VITAMIN B6 + VITAMIN B12 1 VITAMIN B1,B6,B12 1 VITAMIN B1 VITAMIN B6 VITAMIN B12
2 LIDOCAINE + VITAMIN B4,B8,B10 1 LIDOCAINE VITAMIN B4 VITAMIN B8 VITAMIN B10
3 SALICYLIC ACID + TALC 0 SALICYLIC ACID TALC
Your request is a bit ambiguous, since you didn't specify what should happen if both these conditions are true:
Molecules column is not blank.
Vitamin_in_name is not 1.
I assumed that, in this case, the values should come from column C, and so Vitamin_in_name is not really needed for this.
In any case, I would do the following:
Check if column A is blank with ISBLANK.
If column A is blank then (1) use REGEXREPLACE to replace all , from column C with +VITAMIN, and (2) SPLIT using + as separator.
If column A is not blank, use a simple SPLIT on column A, with + as separator.
The resulting formula could be this:
=ARRAYFORMULA(IFERROR(IF(ISBLANK(A2:A),SPLIT(REGEXREPLACE(C2:C,",","+VITAMIN "),"+"),SPLIT(A2:A,"+"))))

How to return a count of fields with a given value in a record?

I have a database table with the following fields :
---------------------
FIELDS : | H1 | H2 | H3 | H4
---------------------
VALUES : | A | B | A | C
---------------------
For a given record (row), I would like to count the number of fields with a value of A. In the above, for example, there are two fields with a value of A, so the expected result would be : 2
How can I achieve this?
I am trying to answer the question from a database point of view.
You have a table with one or more rows and every row has in the four columns either an 'A' or something else. For a given row (or for many rows) you want to get the number of columns that have an 'A' in it.
As one commenter pointed out you can't sum letters but you can check whether or not a value is the one you are looking for and then count this occurence as a 1 or 0. Finally sum those values and return the sum.
SELECT (CASE H1 WHEN 'A' THEN 1 ELSE 0 END) +
(CASE H2 WHEN 'A' THEN 1 ELSE 0 END) +
(CASE H3 WHEN 'A' THEN 1 ELSE 0 END) +
(CASE H4 WHEN 'A' THEN 1 ELSE 0 END) AS number_of_a
FROM name_of_your_table;
For your example row this will return:
NUMBER_OF_A
===========
2
If you have more than one row you'll get the number of As for every row.
I test this it work Thanx for help.
SELECT count(H1) + count(H2) + count(H3) + count(H4) + count(H5) +
count(H6) + count(H7) + count(H8) as TOT
from Table T
where T.H1 = 'A' or T.H2 = 'A' or T.H3 = 'A' or T.H4 = 'A'
or T.H5 = 'A' or T.H6 = 'A' or T.H7 = 'A' or T.H8 = 'A'
group by T.ID
order by 1 DESC
Other solution ...

Google sheet -> filtering a query

I created the following sheet:
https://docs.google.com/spreadsheets/d/1AJmzlBlrDZ0mfb_9aSm83fzZxrwYWOxWGxjNhlfqPLA/edit?usp=sharing
I am trying to find a formula to calculate the totals (C7, C8, C9) and wherever it is copied ie C17, C18, C19)
So for C7 I want to sum column D (Duration) wherever:
the Date (col A) is the same as the total row date (that is A7)
The Category (col E) is Internal
Similarly for So for C8 I want to sum column D (Duration) wherever:
the Date (col A) is the same as the total row date (that is A8)
The Category (col E) is External
and
for C9 I want to sum column D (Duration) wherever:
the Date (col A) is the same as the total row date (that is A9)
Has any category
I tried for C7 -
=QUERY({A:E, arrayformula(N(D:D))}, "select sum(Col6) where Col5='Internal' and Col1 = " & A7 & " label sum(Col6) ''",1)
but I get NA ??? any help ?
-
I wouldn't complicate life with a QUERY() here. Instead, just use FILTER().
Total Internal: =SUM(FILTER(D:D, A:A=A7, E:E="Internal"))
Total External: =SUM(FILTER(D:D, A:A=A8, E:E="External"))
Total All: =SUM(FILTER(D:D, A:A=A9))

Trouble in calculated column over date range in Power Pivot using DAX expression

As per application need, Need to do below task in Power Pivot report. (Not in SQL).
I have two date columns in one table
Column Hears :
/* Column Heads :*/ Activity| City | Start_Date | End_Date
/* Row 1 :*/ A1 | C1 | 01/01/2014 | 05/01/2014
/* Row 2 :*/ A1 | C1 | 06/01/2014 | 07/01/2014
/* Row 3 : */ A2 | C2 | 06/01/2014 | 07/01/2014
/* Row 4 : */ A3 | C3 | 03/01/2014 | 04/01/2014
Expected output like - If user selects date range 02/01/2014 to 07/01/2014
Column Header
City | #StartCount| #EndCount
C1 | 1 | 2
C2 | 1 | 1
C3 | 1 | 1
Here #StartCount is
Need to grouped by City.
Its Count of Distinct Activity
It should consider date boundries as : All activity for which start date 'greater or equeal(>=)' Input Start date and (less than '<') End Date
Here #EndCount is
Need to grouped by City.
Its Count of Distinct Activity
It should consider date boundries as : All activity for which Ends date 'Less or equeal(<=)' Input End date and (Greater than '>') End Date
Could you please suggest me expression to be used for such case.
Calculated measure or dax can be used..
The only way I can match your sample data is to ignore the "distinct activities" requirement in your question, since city C1 has only activity A1 and yet the final result counts to 2.
I'm also probably making a lot of assumptions that may be wrong because your sample data is quite limited. But here's my attempt:
declare #Activities table (Activity char(2),City char(2),Start_Date date,End_Date date)
insert into #Activities (Activity,City,Start_Date,End_Date) values
('A1','C1','20140101','20140105'),
('A1','C1','20140106','20140107'),
('A2','C2','20140106','20140107'),
('A3','C3','20140103','20140104')
declare #Start date
declare #End date
select #Start = '20140102', #End = '20140107'
select City,
SUM(CASE WHEN Start_Date < #Start THEN 0 ELSE 1 END) as StartCount,
SUM(CASE WHEN End_Date > #End THEN 0 ELSE 1 END) as EndCount
from #Activities where Start_Date < #End and End_Date > #Start
group by City
(Some of this relies on SQL Server syntax, but since you haven't tagged your question with a database system, I get to pick)
SQL Server syntax
select activity, city,
SUM(case when (startdate >= '2014/01/02' and startdate <= '2014/01/07') then 1 else 0 End) as IsStart,
SUM(case when (enddate >= '2014/01/02' and enddate <='2014/01/07') then 1 else 0 End) as IsEnd
from temp
Group by activity, city
demo: http://sqlfiddle.com/#!3/b2a64/1

Resources