Combine and transpose - google-sheets

I have a table that looks like this:
Year
Month
Customers
Country
2022
January
12
Argentina
2022
January
4
Australia
2022
January
6
Brazil
2021
December
8
Argentina
2021
December
4
Australia
2021
December
2
Brazil
2021
November
12
Argentina
2021
November
4
Australia
2021
November
14
Brazil
I want to consolidate the year and month columns, and transpose the rest of the data for a result that looks like this:
Year
Month
Argentina
Australia
Brazil
2022
January
12
4
6
2021
December
8
4
2
2021
November
12
4
14
Is there any way to do this in Google Sheets?

Try below QUERY() function.
=QUERY(A1:D10,"select A, B, min(C) group by A,B pivot D order by A DESC")

Use this formula
=QUERY(QUERY({A1:D}, " Select * Where Col1 is not null "),
"Select Col1, Col2, min(Col3) group by Col1,Col2 pivot Col4 order by Col1 Desc")

Related

For a table of dates in a Google Spreadsheet, for each date, find the greatest date for the previous month and previous quarter

I have a table of dates (not sorted). For each row, I need to find:
the RANK the Report Date is
the Report Date's Report Month
the Report Date's Report Quarter
the the immediate previous Report Date
the greatest Report Date in the immediate previous Report Month
the greatest Report Date in the immediate previous Report Quarter
I have 1-4 figured out. I'm not sure how to get 5 and 6.
Here is my data, and the various formulas I have:
Report Date
Report Date Rank
Report Month
Report Quarter
Previous Report Date
Previous Month Report Date
Previous Quarter Report Date
2022-08-19
8
2022-08
2022 Q3
2022-08-03
???
???
2022-06-08
15
2022-06
2022 Q2
2022-05-31
2022-09-23
2
2022-09
2022 Q3
2022-09-16
2022-07-18
12
2022-07
2022 Q3
2022-06-27
2022-08-26
6
2022-08
2022 Q3
2022-08-22
2022-09-30
1
2022-09
2022 Q3
2022-09-23
2022-08-03
9
2022-08
2022 Q3
2022-08-02
2022-09-09
4
2022-09
2022 Q3
2022-09-02
2022-09-16
3
2022-09
2022 Q3
2022-09-09
2022-06-27
13
2022-06
2022 Q2
2022-06-14
2022-06-14
14
2022-06
2022 Q2
2022-06-08
2022-05-31
16
2022-05
2022 Q2
2022-05-24
2022-07-26
11
2022-07
2022 Q3
2022-07-18
2022-08-22
7
2022-08
2022 Q3
2022-08-19
2022-04-26
18
2022-04
2022 Q2
2022-08-02
10
2022-08
2022 Q3
2022-07-26
2022-05-24
17
2022-05
2022 Q2
2022-04-26
2022-09-02
5
2022-09
2022 Q3
2022-08-26
Formulas:
B1:
={
"Report Date Rank";
ARRAYFORMULA(
IF(
A2:A <> "",
RANK(
A2:A,
A:A
),
)
)
}
C1:
={
"Report Month";
ARRAYFORMULA(
IF(
A2:A <> "",
TEXT(A2:A, "YYYY-MM"),
)
)
}
D1:
={
"Report Quarter";
ARRAYFORMULA(
IF(
A2:A <> "",
YEAR(A2:A) & " Q" & ROUNDUP(MONTH(A2:A)/3, 0),
)
)
}
E1:
={
"Previous Report Date";
ARRAYFORMULA(
IF(
A2:A <> "",
XLOOKUP(
B2:B + 1,
B:B,
A:A,
),
)
)
}
For 5 and 6, I was thinking I could RANK the Report Month and Report Quarter columns, but I don't know how to use that information to get the greatest date in the previous "rank".
So, for example, for 5, for the row with 2022-08-19 for Report Date, 5 and 6 would be:
Previous Month Report Date = 2022-07-26 because that is the greatest Report Date in the 2022-08-19's previous month
2022-08-19's Report Month is 2022-08
The previous Report Month is 2022-07
The largest Report Date in 2022-07 is 2022-07-26
Previous Quarter Report Date = 2022-06-27 because that is the greatest Report Date in the 2022-08-19's previous quarter
2022-08-19's Report Quarter is 2022 Q3
The previous Report Quarter is 2022 Q2
The largest Report Date in 2022 Q2 is 2022-06-27
Try approximate match (next smallest) on the sorted dates:
=ArrayFormula(if(A2:A="",,xlookup(eomonth(A2:A,-1),sort(A2:A),sort(A2:A),,-1)))
and
=ArrayFormula(if(A2:A="",,xlookup(eomonth(A2:A,-(mod(month(A2:A)-1,3)+1)),sort(A2:A),sort(A2:A),,-1)))
EDIT
On reading the small print of Xlookup, I can see that sorting is actually unneccessary because it does not assume array is in order unless you specify 2 as the last argument see docs so this also works
=ArrayFormula(if(A2:A="",,xlookup(eomonth(A2:A,-1),A2:A,A2:A,,-1)))

How tranpose the data of more than 1 cell to only 1 cell on google sheets?

I have the following column :
A1
Miu Kei Yuk
3354
of
2018
8 April 2022
and need to separate it into 3 columns :
3354 of 2018 Miu Kei Yuk 8 April 2022
So the first and the fifth row are correct, but the row number 2, 3 and 4 needs to be in only 1 cell.
I tried transpose(A1:A5) but iu results in :
Miu Kei Yuk domingo, março 07, 1909 of 2018 8 April 2022
Is it possible to do it ?
try:
={A2&" "&A3&" "&A4, A1, A5}
or:
={A2&" "&A3&" "&A4\ A1\ A5}
For Portuguese Locale use this formula or Make a copy of this example.
={TEXTJOIN(" ";1;A2:A4)\
A1\
A5}
For United States locale use this formula
={TEXTJOIN(" ",1,A2:A4),
A1,
A5}

Calculate cumulate average values using a Google sheet/excel calculated field

I'm trying to find a way to aggregate average values in a Google sheet in a pivot table using calculated fields.
Here's my data:
Close Date
Amount
March 2020
£60,000.00
April 2020
£15,000.00
April 2020
£90,000.00
April 2020
£220,000.00
April 2020
£50,000.00
May 2020
£100,000.00
May 2020
£440,000.00
May 2020
£15,999.00
May 2020
£85,000.00
May 2020
£500,000.00
June 2020
£270,000.00
June 2020
£210,000.00
July 2020
£60,000.00
July 2020
£35,000.00
July 2020
£75,000.00
By using the following calculated field, I can calculated each month's average:
=AVERAGEIFS(B2:B17,A2:A17,">="&Date,A2:A17,"<="&EOMONTH(Date,0))
Close Date
Average Result
March 2020
£60,000.00
April 2020
£93,750.00
May 2020
£228,000.00
June 2020
£240,000.00
July 2020
£56,666.67
However, what I want to do is cumulate the average values like so:
Close Date
Cumulated Average Result
March 2020
£60,000.00
April 2020
£153,750.00
May 2020
£381,750.00
June 2020
£621,750.00
July 2020
£678,416.67
I realise I could add an additional formula column in the sheet itself, but I'd much prefer to do this via a calculated field if possible.
Many Thanks
Since you have tagged both Excel and Sheets, the solution in Excel is to merely select to show the values of the Average column as a Running total (in the Value Field Settings tab).
cumulative running average:
=ARRAYFORMULA({UNIQUE(TEXT(FILTER(A1:A, A1:A<>""), "mmmm e")), MMULT(TRANSPOSE((
SEQUENCE( COUNTUNIQUE(TEXT(FILTER(A1:A, A1:A<>""), "e-m")))<=
SEQUENCE(1, COUNTUNIQUE(TEXT(FILTER(A1:A, A1:A<>""), "e-m"))))*
QUERY({TEXT(A1:A, "e-m"), B1:B},
"select avg(Col2) where Col2 is not null group by Col1 label avg(Col2)''")),
SEQUENCE( COUNTUNIQUE(TEXT(FILTER(A1:A, A1:A<>""), "e-m")), 1, 1, 0))})

How to get days between two dates in google sheet

I have been trying to get the number of days between two dates in google-sheet but sometimes it gives an integer and sometimes it gives another date. How to get only the integer?
Shared public sheet (sheet name DS):
https://docs.google.com/spreadsheets/d/10NzbtJhQj4hQBnZXcmwise3bLBIAWrE0qwSus_bz7a0/edit#gid=517697699
Example
SN COMPANY AppliedDate DaysSince Today
-----------------------------------------------------------
2 McDonald Feb 17, 2021 54 1
3 Nielson Feb 17, 2021 Apr 20, 1900 2 **This should be number NOT date
4 Edelman Feb 17, 2021 111 3
5 Upstart Feb 19, 2021 Apr 18, 1900 1
6 Root Inc. Feb 19, 2021 Apr 18, 1900 2
Required
For the column DaysSince I would like to have only number. I want number between two dates but sometimes the same formula works sometimes does not work.
Is there any other methods to get number of days between two dates?
Go Format > Number > Number to format you entire column. Your problem is that your format is set as Automatic.

Have only Tuesdays and Fridays repeating

Is it possible to drag a repeating pattern of Tuesdays and Fridays repeating in Google Sheets? The type of output I'm looking for would be this:
Tuesday, June 2, 2015
Friday, June 5, 2015
Tuesday, June 9, 2015
Friday, June 12, 2015
...
and then drag down to continue the pattern...
When I do it now, it continues incrementing by he number of days between Tuesday and Friday.
Thanks!
Maybe you can try a formula:
=query(ArrayFormula({(date(2015,6,2)+row(A1:A1000)-1), weekday(date(2015,6,2)+row(A1:A1000)-1,2)}), "select Col1 where Col2 matches '"&JOIN("|", 2, 5)&"' limit 10")
where the date() function holds the starting date
and the limit part limits the output to whatever number you want.
See if that works ?
EDIT: If you only want the tuesdays and fridays from the list of dates in col A, try:
=filter(A2:A, (WEEKDAY(A2:A)=3)+(WEEKDAY(A2:A)=6))
Then copy the output and paste in col A as 'values only'.

Resources