Dealing with overlaping week and year numbers in Excel - excel

A new year with new problems! I have several Excel based rapports that pull data from an Oracle table. However i noticed a problem related to year and weeks in Excel. Here is and example:
The formula i use now is Week(A1;21) for the week and Year(A1) for the year.
Is there a way that i can get the correct year for the whole week based on the date in excel (see week 1 of 2015 in the picture above)
The result i want is this:

This is a possible solution:
=YEAR(A1)+AND(WEEKNUM(A1;21)=1;MONTH(A1)=12)

Related

Excel, trying to split rent for the number of days in a month, per month for the whole year

So I am trying to calculate rent for each month. The problem I am facing is with the fact that starting date and ending date could be in the middle of a month.
For example:
Rent = 10,000
Starting date = 15/04/2020
Ending date = 10/10/2020
I want my excel Sheet to split accordingly as below:
First sample row of the excel
In my excel sheet, I have different amounts for rent and various start/end dates.
This is what I have tried but failed miserably:
> =$F3/(12*DAY(EOMONTH(H$1,0)))*(IF(MONTH($C3)<=MONTH(H$1),IF(MONTH($C3)=MONTH(H$1),(EOMONTH($D3,0)-$D3),DAY(EOMONTH(H$1,0))),0))
Where F is where the RENT is, H1 is January, C3 is start date, D3 is end date. I'm hoping it to work when I autofill the formula across the whole sheet.
Please help!
#Hooded0ne I tried your formula for all examples in my sheet and there seems to be an issue for some cases:
When start date is 2019 and end date is 2020. This should only show rent till April.
Same case as above, December 2020 is only till the 14th, it should only calculate for the first 15 days
Blockquote
Does this work for you?
=MAX((MIN(EOMONTH(K1,0),$D$3)-MAX(K1,$C$3)+1)/DAY(EOMONTH(K1,0))/12*$F$3,0)
Edit: It should work for multiple years, if you have a specific example, please add it to your original post.

filter data between 2 dates in excel using VBA

i was wondering if someone can help. i have tried some formulas but cant seem to work this out. i have a list of data with lots of dates some duplicate dates which are fine. i have data on a daily basis from 2015-2018. my aim is to try to put a number against each week between 2 dates so Monday-Sunday representing a week. so if the date falls between to dates bring back the week number. but of course there is a long list of date ranges and week ranges. does anyone know a formula or code to read to date and look between 2 separate dates and bring back a week number
thanks
Muj
For a given date, weeknum() will return the week number:

Defining current year and next year in code

How do I split up my data by current year and next year?
I will have one tab dedicated to current year (2018) and one dedicated to next year (2019).
My issue is that once January 1, 2019 hits, my code will be looking at 2019 as the current year and 2020 as the next year.
Two solutions I can come up with.
First, I format the Date Column for "YYYY" (ie. 2018). Then on a separate tab, I will have a cell box with the current year in it (can be changed each year). The countif formula will pull only items that have years equal to the Cell box.
Second. I have the date column set for "YYYY" on my spreadsheet. The column next to it will be set to the current year "YYYY". I will subtract the two in order to get "1's and 0's". Then my Countif formulas will look for "1's and 0's" in the subtraction column depending on which sheet you are looking at.
Is there a better idea?
Instead of hardcoding the year, you can grab the current year using:
Year(Now())
and next year would be :
Year(Now()) + 1
You could just show a user form that let's the user specify the relevant years for calculation via two date pickers or simple input boxes.
Or you might even stay away from Excel/VBA entirely and solve this by using a (e.g.) python script that uses your excel files (or some CSV) as source.
This might be a good alternative if you don't really need VBA/Excels functionality or if it even limits you in some way, like creating reports.

Month & Week grouping in excel pivot tables with some empty data

I am working to group data in excel and I am trying to sort the input dates by month and week. I've found a number of ways to group by weeks (including grouping the date by 7 days and adding a helper column in the pivot table that numbers the weeks), but I'm having a problem viewing months and weeks without data.
For example, in my data set during the month of October, 2 of the weeks have no input. When I try to make the pivot table "show rows with no data" it shows every week in the year, not only the weeks during the month of October.
I would like be able to show every week during the month of October, including those without data, without showing every week in the year. Has anyone encountered a similar issue? I'm on Excel 2016 but my colleague has the same issue on Excel 2013.
Thanks!
Here is a quick screenshot of the pivot table from the data. I am trying to make all of the weeks in the month of October show up regardless of whether or not there is data, but I don't want to see all of the weeks in the date range. I have sample data input from September 16th, 2018 to January 1st, 2019
Update for anyone looking to do this themselves:
I couldn't figure out a way to do this with Pivot Charts. They lack the ability to group by multiple days as well as by months and years. Instead, I used VBA to select the desired data from the pivot table by checking for the number of the month in each row. (mm/dd/yyyy - mm/dd/yyyy is the format pivot tables use to group days).
I added a dummy row which copied the date ("Date 2") and used that, grouped in 7 days, as the rows for the pivot table. Because I wanted to show items with 0 data I selected that option, which shows every group of 7 days from the first day entered until the last day entered. I used the original Date with Month and Year auto groups to insert Slicers to sort the data.
In VBA you can check which Slicers are selected and use that to determine the range of months you want to display on the inserted chart. This way you can look at one or two months at a time but still show weeks with no data.
While this solution is not particularly elegant, it did allow for a dynamic use of the data that can be adjusted to view specific months or years as was desired. Some useful resources for this method are included below. Again, it is an ugly way to get the desired result but if it works it works!
https://peltiertech.com/referencing-pivot-table-ranges-in-vba/
https://peltiertech.com/create-update-chart-using-partial-pivot-table/

Convert date in Excel to its respective week of the month

Hopeful you can help me out.
I have an Excel spreadsheet open. The spreadsheet has two columns that I need assistance with.
The first column are dates and times that reflect a ticket that opened. The second column reflects dates and times that a ticket closed.
I am needing to correlate all the dates of which every ticket opened and closed to its respective week of the month. So if I have 20 tickets that opened up between the days of 2/22/15 - 2/28/15(all these dates are in the same column fyi...), then I will be needing to somehow correlate these tickets in my spreadsheet to some form of data to be used in a line stack chart.
An exec has laid this on my lap. I don't look useless and I would like a little assistance as to how to perform such a task. Formulas in Excel...Vlookup....or using Pivot Tables....please assist!
convert date in excel to its respective week of the month
in conjunction with the date range example:
=INT((DAY(A1)-1)/7)+1
In column 3 use the =Weeknum(A1, 1) formula to get the week number of the date in column a. The second argument lets you determine what you want for the beginning of the week to be.
In column 4 do the same for column b. This will give you the week ticket opened/closed respectively. Add column 5 to be the difference in weeks which can be used in a pivot table to show the distribution of tickets and weeks to resolve, etc.
Reply back if you have further needs.
Firstly get the week num of the first day of the month -1
A1 = 01/02/2018
B1 = =WEEKNUM(A1)-1
Then calculate the individiual ticket week numbers and take the week number before the first week of the month away from the returned value. You may need to format the cells as numbers as some reason Excel thinks its a date
Open Week = =WEEKNUM(OpenDateCell)-$B$1
Close Week = =WEEKNUM(CloseDateCell)-$B$1
Representative Image:

Resources