Google Sheets - Expanding dataset according to months between 2 dates - date

I would like to be able to expand a dataset to include one row per "person" per month, filtered by Start and End Date.
Consider the example below:
This is the desired outcome
Inputs are a start and end date, which could be anywhere between the start of a given financial year (01/04/20XX) and the end of that financial year (31/03/20XY).
The output rows contain each month comprised between these 2 dates for which there is a matching entry in the input (see example output)
I have an example sheet here.
Any help would be appreciated, thanks

Try:
=ARRAYFORMULA(SPLIT(UNIQUE(QUERY(FLATTEN(IF(DAYS(C2:C4,B2:B4)>=SEQUENCE(1,1000,0),A2:A4&","&TEXT(B2:B4+SEQUENCE(1,1000,0),"YYYY-MMM")&","&D2:D4,"")),"where Col1 is not null")),","))
Result:
This works however the only limitation is you have to manually edit the formula to specifically define the End range. It crashes when I set it to use the whole column using the formula below:
=ARRAYFORMULA(SPLIT(UNIQUE(QUERY(FLATTEN(IF(DAYS(C2:C,B2:B)>=SEQUENCE(1,1000,0),A2:A&","&TEXT(B2:B+SEQUENCE(1,1000,0),"YYYY-MMM")&","&D2:D,"")),"where Col1 is not null")),","))
I am assuming this is because of the Query function which runs a Google Visualization API Query Language query across data making it very long and heavy processing.
Explanation:
To explain how this works using the formula from this link: Google sheets - List of dates between a list of start and end dates to get the dates between, but I changed the IF to return all combined 4 columns. Converted it to date format using TEXT (YYYY-MMM). I then used the UNIQUE to remove duplicates so it will only show the months. Then make use of SPLIT to split across 3 columns.
References:
Get dates between 2 dates
TEXT
UNIQUE
QUERY
SPLIT
Hope this helps!

Related

How can I filter by a group of individual dates in Google Sheets?

I have a group of individual dates on one sheet, and I'm looking for a quick way to filter by each individual date (not the range) on another sheet.
Group of individual dates
Values I'm trying to filter
Thank you.
I tried separating the dates by comma and putting them into the 'filter by - exact date' part of the filter tool. It will only recognize one date, not multiple.
I'm guessing what you may want to do. But if you want to filter by formula your range according to the dates match your second range you can do something like this:
=FILTER (Sheet1!A:O,INDEX(IFERROR (MATCH(Sheet1!A:A,Sheet2!A:A,0))))
Change the ranges accordingly. I used sheet 2 as the set of dates you wanted to filter by

Adding Columns using google sheets

Is there a way I can add a total of a column if the numbers are imported from a different sheet with google sheets? and matching a pair of dates?
=SUMIFS($S$8:S47,$O$8:$O47,">="&T$51,$O$8:$O47,"<="&$V$51)
most likely this is the issue of QUERY. query likes to "assume" the type of dataset (numeric/plain text) and 90% of time it assumes it wrongly so you either end up with empty columns or missing values. use in S6:
=IMPORTRANGE("1nC7e8za4_SjIAbPsRv4loQ8CHinwcp0J43LcyG0qopM", "August 2022!i3:j45")

How do I use Tableau to populate the count of each dimension over a time period?

How do I populate the number of purchases and sales per day in tableau?
Here is my Sample Data:
In my first attempt, sales numbers are not counted to the exact date.
In my second attempt, I tried to tabulate by dropping sales date into the rows. However, it returned two figures - purchases and sales.
I have also tried Calculated Field but Tableau is unable to do a "for loop" like python.
First attempt:
After dropping Sales Date into the Rows. This is what I get:
Is there any way to populate it like this? Please help, I am still new to tableau. Special thanks to Fabio Fantoni for the first solution!
Desired Format:
I have another sample data (refer to sample data 2) which I would like to populate in the desired format (refer to desired format 2). In Sample Data 2, the purchase date "15/12/2020" is not reflected in sold dates.
My apologies but I may require some guidance as I am still new to tableau. Thank you in advance.
Sample Data 2:
Desired Format 2:
Based on this sample:
In order to bypass your double count for two different date columns, you may want to cross join your original data with a copy of it on original.Purchase = support.Sold, like this:
Doing so, you just have to create two calculated fields:
count Purchase:
count([Purchase Date])
count Sold:
Count([Purchase Date (Foglio11)])
The only thing you have to pay attention to is that in the second calculus you have to count Purchase date due to your "inverted" cross join.
You should get something like this:

In Tableau, is there a way to only show the first and last date in the table output using the date filter

Tableau will generally show every single date within table output of the date ranges filtered for. Is there a way to only show the first and last date in the table for the date of ranges selected?
I created an image of the desired output in excel. Link below:
Desired output example
Thank you in advance!
The feature that will address your goal is called a Level of Detail (LOD) calculation. They have many uses and take various forms. I suggest reading about the in the online help.
But, to answer your question, the LOD calc to find the first (i.e. minimum) value in a date field called, say, Transaction Date, is;
{ MIN([Transaction Date]) }
The formula for the latest value is left as an exercise for the reader 😊

Retrieving all entries 10 days prior to days in table, which matches where clause

I have a random table of data - with dates and numbers:
Date Open Volume abschange
2016.12.08D00:00:00.000000000 11035.76 1.74835e+008 1.30177
2016.12.09D00:00:00.000000000 11170.18 1.0383e+008 0.2994598
2016.12.12D00:00:00.000000000 11198.42 8.98117e+007 0.07331357
...
2016.12.30D00:00:00.000000000 11443.31 4.18109e+007 0.3298871
2017.01.02D00:00:00.000000000 11426.38 4.74561e+007 1.504853
So from this table, i would like to be able to create a list, which holds all the entries from 10 days prior to the days, which has abschange>1.
I thought it would be easiest to start with a focus on those dates:
Date abschange
---------------------------------------
2016.12.08D00:00:00.000000000 1.30177
2017.01.02D00:00:00.000000000 1.504853
2017.01.25D00:00:00.000000000 1.099709
2017.01.31D00:00:00.000000000 1.344625
2017.02.06D00:00:00.000000000 1.016427
2017.02.21D00:00:00.000000000 1.265196
Then create a flat list:
mynewdates: raze tablewithDateAndabschange each
which gives me:
2016.12.08D........ 2017.01.02D......
Then i get stuck, when i want to add 10 prior dates for each entry in this list.
Could i actually get my wanted result in one line of code, based on the first table or should i follow the path i am on ?
For both - if possible, what would the possible solution to this be ?
If my understanding is correct your requirement is:
for each date for which abschange>1, get last 10 dates before this date from table.
Below query will create that map. It is based on following assumptions:
Date column is unique and ordered(ascending) as it appears from your example.
If above condition is not true then it will require a minor change in below query to work with duplicates and unordered list.
Table is not keyed.
q) (tbl[`Date]a)!b#'where#'not null b:tbl[`Date] -1+(a:where 1<tbl`abschange)-\:til 10
UPDATE: Based on discussion in comment section.
Just add the second step to check if dates list for first result is empty. In that case generate last 10 dates from that date.
Finally it generates the table where each row contains prior dates(max 10) for each date with abschange>1.
q)d:b#'where#'not null b:tbl[`Date] -1+(a:where 1<tbl`abschange)-\:til 10
q)d[0]:$[0=count d 0;(t[`Date]a 0)-1+til 10;d 0]
q)([]dates:d)