[Solved] Sort by date within a period
[Solved] Sort by date within a period
Up until now, have maintained a Calc spreadsheet manually. Add/modify/delete rows, shift rows here and there. Can I sort the dates within a period somehow ?
See attached screendump. Yes, some of the dates don't fall within the correct period, but the objective is to be able to sort those dates within a period automatically. Can this be done with a Python script ?
See attached screendump. Yes, some of the dates don't fall within the correct period, but the objective is to be able to sort those dates within a period automatically. Can this be done with a Python script ?
Last edited by MrProgrammer on Thu Nov 21, 2024 12:32 am, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
LibreOffice Version: Version: 6.4.7.2 on Kubuntu 20.04.4
Re: Can I sort by date within a period ?
I'm not sure I understand your goal. Maybe you can get what you want by copying down the start date, or end date, of the period and sorting on both that date and the date in column E. It would be easiest to put a header on each column and remove the blank rows.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Can I sort by date within a period ?
If I sort B then E, it comes out as per screendump.
Somehow, the dates in E need to have a period assigned, so that a sort on Period (B) then date (E) will give the correct order. There is a sheet with the periods.
If I can use Python in a script to assign the period 'row number' to each row, where there is a date in E. That value would have to be inserted in a (new) Column A. There may be some other fine tuning of course.
Somehow, the dates in E need to have a period assigned, so that a sort on Period (B) then date (E) will give the correct order. There is a sheet with the periods.
If I can use Python in a script to assign the period 'row number' to each row, where there is a date in E. That value would have to be inserted in a (new) Column A. There may be some other fine tuning of course.
LibreOffice Version: Version: 6.4.7.2 on Kubuntu 20.04.4
Re: Can I sort by date within a period ?
Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.8.3.2; SlackBuild for 24.8.3 by Eric Hameleers
---------------------
Apache OpenOffice 4.1.15
LibreOffice 24.8.3.2; SlackBuild for 24.8.3 by Eric Hameleers
---------------------
Roses are Red, Violets are Blue
Unexpected '{' on line 32
.Re: Can I sort by date within a period ?
Thanks, I will look at Pivot table; have seen a few examples. Lookup may also work ? - https://wiki.openoffice.org/wiki/Docume ... P_function
LibreOffice Version: Version: 6.4.7.2 on Kubuntu 20.04.4
Re: Can I sort by date within a period ?
Create a (temporary) column with the dates from both B and E. If at least one of them is always empty, just add them, otherwise use a test to see if one is empty, then use the other one. Then use that column to sort.
AOO 4.1.15 & LO 24.8.3 on Windows 10
Re: Can I sort by date within a period ?
The sheet named 'Periods' now has a row number by using =row()
I got an Err:502 when trying to lookup the periods sheet and return the row number. Obviously the syntax or referenced cells are incorrect
I got an Err:502 when trying to lookup the periods sheet and return the row number. Obviously the syntax or referenced cells are incorrect
Code: Select all
=VLOOKUP(D26,$Periods.$B$2,$Periods.$C$113,0)
LibreOffice Version: Version: 6.4.7.2 on Kubuntu 20.04.4
Re: Can I sort by date within a period ?
Please note the syntax for VLOOKUP:
=VLOOKUP(SearchCriterion; Array; Index; SortOrder)
SearchCriterion is the value searched for in the first column of the array.
Array is the reference, which is to comprise at least two columns.
Index is the number of the column in the array that contains the value to be returned. The first column has the number 1.
SortOrder is an optional parameter that indicates whether the first column in the array is sorted in ascending order. Enter the Boolean value FALSE or zero if the first column is not sorted in ascending order. Sorted columns can be searched much faster and the function always returns a value, even if the search value was not matched exactly, if it is between the lowest and highest value of the sorted list. In unsorted lists, the search value must be matched exactly. Otherwise the function will return this message: Error: Value Not Available.
=VLOOKUP(SearchCriterion; Array; Index; SortOrder)
SearchCriterion is the value searched for in the first column of the array.
Array is the reference, which is to comprise at least two columns.
Index is the number of the column in the array that contains the value to be returned. The first column has the number 1.
SortOrder is an optional parameter that indicates whether the first column in the array is sorted in ascending order. Enter the Boolean value FALSE or zero if the first column is not sorted in ascending order. Sorted columns can be searched much faster and the function always returns a value, even if the search value was not matched exactly, if it is between the lowest and highest value of the sorted list. In unsorted lists, the search value must be matched exactly. Otherwise the function will return this message: Error: Value Not Available.
Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.8.3.2; SlackBuild for 24.8.3 by Eric Hameleers
---------------------
Apache OpenOffice 4.1.15
LibreOffice 24.8.3.2; SlackBuild for 24.8.3 by Eric Hameleers
---------------------
Roses are Red, Violets are Blue
Unexpected '{' on line 32
.Re: Can I sort by date within a period ?
The formula only works if there is an exact match on the date, otherwise it returns #N/A
I need to do a lookup on the date range, so that if the date is within the range of dates in the sheet "Periods" , it returns the value.
Have tried it with and without the $ sign , in reference to the sheet name and cells.
Code: Select all
=VLOOKUP(E26,$Periods.$B$2:$Periods.$C$113,1,0)
Have tried it with and without the $ sign , in reference to the sheet name and cells.
LibreOffice Version: Version: 6.4.7.2 on Kubuntu 20.04.4
Re: Can I sort by date within a period ?
This would be far easier to explain if you uploaded a spreadsheet instead of images. Make a copy of your document and delete the data in columns beyond E if you don't want to share that.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Can I sort by date within a period ?
#NA is the same as Error: Value Not Available mentioned in my previous post.
It appears that your first column in the Array may be sorted; in which case you might try setting the fourth parameter, SortOrder, to TRUE.
Although I am not sure that VLOOKUP is going to be a solution for your problem if you want a range of values to be returned; this function only returns a single value.
If you continue to have problems, it would be better if you could upload a sample spreadsheet file - not an image - containing sample data and a description of the result you are seeking. How to upload a file
It appears that your first column in the Array may be sorted; in which case you might try setting the fourth parameter, SortOrder, to TRUE.
Although I am not sure that VLOOKUP is going to be a solution for your problem if you want a range of values to be returned; this function only returns a single value.
If you continue to have problems, it would be better if you could upload a sample spreadsheet file - not an image - containing sample data and a description of the result you are seeking. How to upload a file
Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.8.3.2; SlackBuild for 24.8.3 by Eric Hameleers
---------------------
Apache OpenOffice 4.1.15
LibreOffice 24.8.3.2; SlackBuild for 24.8.3 by Eric Hameleers
---------------------
Roses are Red, Violets are Blue
Unexpected '{' on line 32
.Re: Can I sort by date within a period ?
Inserting/attaching screenshots to a post instead of an example file is an ingenious way to give very little information using up huge areas and causing lots of net load.
Also volunteers of the forum should be glad to be invited to create themselves the examples needed to test ways to possible solutions.
Getting serious:
Screenshots should only be inserted if the post is about an issue with the view. Even in this case it's mostly better to insert the image into an example file which then is attached.
Also volunteers of the forum should be glad to be invited to create themselves the examples needed to test ways to possible solutions.
Getting serious:
Screenshots should only be inserted if the post is about an issue with the view. Even in this case it's mostly better to insert the image into an example file which then is attached.
On Windows 10: LibreOffice 24.8.2 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
Re: Sort by date within a period
Thanks for all the help and replies. Point taken about using images. Created some test data.
1. Sheet Periods - Contains the from and to dates of each period, and the row number (which for this exercise I will call the period number).
2. Use VLOOKUP (or some other function) to search through the Periods data. As you can see, it only works where the date is an exact match of a period 'from' or 'to' date.
3. Once the proper period number (row number from Periods sheet) is returned, a sort can be done. Most likely, column A - ascending, Column B - descending, column D - ascending
Checking if a value is within a range at viewtopic.php?t=90294
1. Sheet Periods - Contains the from and to dates of each period, and the row number (which for this exercise I will call the period number).
2. Use VLOOKUP (or some other function) to search through the Periods data. As you can see, it only works where the date is an exact match of a period 'from' or 'to' date.
3. Once the proper period number (row number from Periods sheet) is returned, a sort can be done. Most likely, column A - ascending, Column B - descending, column D - ascending
Checking if a value is within a range at viewtopic.php?t=90294
Last edited by cephas on Wed Nov 20, 2024 12:48 am, edited 1 time in total.
LibreOffice Version: Version: 6.4.7.2 on Kubuntu 20.04.4
Re: Sort by date within a period
A2: =B2+D2, then use the fill handle up to A19 and sort on column A.
AOO 4.1.15 & LO 24.8.3 on Windows 10
Re: Sort by date within a period
I tested that on rows 2 to 6 and it does put the rows in the correct order. Can you explain the 'fill handle' please ? Where/how that is applied.
LibreOffice Version: Version: 6.4.7.2 on Kubuntu 20.04.4
Re: Sort by date within a period
The small square at bottom right of the active cell. Hover the mouse pointer over it and the pointer will change; in my case to a cross. Click to grab the handle and drag as needed.Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.8.3.2; SlackBuild for 24.8.3 by Eric Hameleers
---------------------
Apache OpenOffice 4.1.15
LibreOffice 24.8.3.2; SlackBuild for 24.8.3 by Eric Hameleers
---------------------
Roses are Red, Violets are Blue
Unexpected '{' on line 32
.Re: Sort by date within a period
Great, thanks. That has the same effect as when I copy cell A and then paste down a column, from A3 to A19robleyd wrote: ↑Wed Nov 20, 2024 1:13 am The small square at bottom right of the active cell. Hover the mouse pointer over it and the pointer will change; in my case to a cross. Click to grab the handle and drag as needed.
See also Speeding Up Data Entry.
The sort works perfectly, great.
So, in summary VLOOKUP is unable to handle a range of dates and return a value where the search item is WITHIN the range.
LibreOffice Version: Version: 6.4.7.2 on Kubuntu 20.04.4
Re: Sort by date within a period
By the way, you can get your period number from the Date column using a formula like this in row 3
Your periods start every 28 days. Your period #0 stared March 18, 2018. That day has the value 43177, which is the number of days since 12/30/1899. Subtract 43177 from any date, divide by 28, take the integer part of the result, and you have the number of 28 day periods since March 18, 2018.
Code: Select all
=INT((D3-43177)/28)
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Sort by date within a period
Okay thanks, I'll try that.
LibreOffice Version: Version: 6.4.7.2 on Kubuntu 20.04.4
Re: Sort by date within a period
Thanks for the help with this, it's working fine now.
LibreOffice Version: Version: 6.4.7.2 on Kubuntu 20.04.4