Pivot Table - How do I make 'base item' for 'difference from' dynamic using vba? - excel

I am attaching the macros, and desired result as an image.
So, I am running a macro to find differences (amounts) between dates that are selected from the slicer, using 'previous' as the base item in 'difference from' and it works perfectly. Now, I want to run another macro where the difference should be from the oldest of the selected dates. I hardcoded it once with a set of dates where the oldest date will always be 31-12-2021. But if I want to compare the data from 2021 then I need to find differences from 31-12-2020, basically the end of previous year. How do I make this base item dynamic so that it's either last end of year date or the oldest chosen date if someone is manually choosing the dates from the slicer?
My Macros
The desired pivot table result
Can I have the user enter the oldest date in a cell and have the vba code refer to that cell or something?
Any help would be appreciated. Thanks!

Related

I require to change the cell formulas to values only when a certain date passes

I have a pivot table on excel that automatically updates with values every day.
I have columns next to the pivot table for EACH DAY that grabs data from the updated pivot table using a simple formula, for example I11-V11.
However, when the date for today passes, i want the cell in the specific column for that date to change to a value i.e be fixed.
Is there a way that this could be done?
You want a snapshot of the data. Manually, you could copy and paste the data over itself with Paste Special > Values.
You can create a VBA macro for that, but the trigger for the macro would still have to be manual. Because if it is dynamic, once the header date is in the past, any formula will have already updated dynamically and yesterday's values will be gone.
So, either manually copy/paste values (or fire up the macro to do that), or add a date column to the data source, so a formula can associate a value with the correct date.

Guide me Regarding Compare the Value of Cell contain date and other cell contain Drop down list

Hy Every One, I need help in excel formula, I have two sheets, sheet1 for sale tracker, sheet two for goals tracker, I used Now() to enter date automatically, and its working fine, Next in goal sheet, I use =Sumif() to calcualte various category totals and refer them in cell. Its also working fine. But I want to track record according to month and category. Like I have 6 categories detail is as under,
Sales Tracker
In the First picture Column Date consist of formula "=IF(ISBLANK(B5),"-",TODAY())" and it display the name of month like "October"
While in second picture there is a drop down list of "Month" Column.
1- I want to use if statement like =if(Date=Month, Sum(Revenue Secure column Data), "-") But its not working the formula I wrote here is an example....
2- I want when I select any month from second sheet like January, February, It should calculate sum from picutre one data and only show the sum of january etc.
Please help me, this is eating my brain a huge,,,,,,:)
Thanks in advance....
In short my question is how can I use If statement to compare value of cell that contain formula and other that contain drop down list?
Or use the MONTH function to change your date to a number 1 to 12 corresponding to the month. Then have the combo return a number for the month chosen. It might be faster using integers than test
I Believe you have to compare the month and not the whole date.
You can do TEXT(NOW();"mmmm") to get the full month name of the current data (in the language of excel) and then compare it to your drop down.
If you replace the NOW() with any data it works as well.

Filtering Excel Table with date in multipe columns

I have a table that has two date columns. For simplicity, lets say and "in date" and "out date." I would like to filter the table to see activity of a date in either column.
With the standard autofilter, it will execute filter where "in date" and "out date" are both the date it will show. I don't know of a way to do if "in date" or "out date" = user date. I want to filter the table row when either date is the same as the selected date. Thus, showing all rows that contain the date specified.
Can anyone help on a way to do this? I am trying to do this VBA code so that the sheet can be very simple for the user.
I think advanced filter is the functionality you need. How are you "selecting" the date to be used for the filter?
If you want an OR filter, in the criteria put the target date on separate lines (on the same line is an AND).
A B
1 InDate OutDate
2 7/17/17
3 7/17/17
If you reference your selected value in both date cells they will both update when you select your date.
Another helpful tip when doing advanced filter is define a named range for your data set, it makes executing the filter easier. Defining names for your criteria area and output area are also helpful.
When you get the filter working, record a macro (using your defined names), then add a button to the worksheet that launches the macro.
I've done similar things with the input being a datepicker object.
Good luck!

How to show a value in one cell when current week is in another cell in excel

My first time to this forum.
I am a free range poultry farmer and I am trying to make spreadsheets to monitor my flocks. I have made the flock specific input sheets and now working on getting information for all of them into one summary sheet.
My question is...
I have the age of the birds going down column A also I have dates by week end date going down Column B... I would like to know how to have it that in one summary cell when the current date falls into one of the weeks listed in Column B that the corresponding cell in Column A is shown in that Summary cell (showing the current age of the flock). I would like this obviously auto update when the date progresses into another week.
Can any one help??
Thanks
Put the current date in the header (=TODAY() function or variations).
Name the current date cell (e.g. Current_date)
If your data are in table format I recommend putting them in a Table, this will insert your formulae to any new row started. If you dislike them you can simply create filters.
Use the formula in say C5 "=B5=Current_date" This will give you a logical expression, TRUE or FALSE. You can filter for TRUE to see the flocks to sell/cut.

Excel Advanced Filtering Issues - Advice Needed

So basically I have a main table, and I want to filter that data to another table (normally easy) but I want this based upon 2 criteria. e.g. I want to filter the data of a specific department but only for the current month. The way I display the current month in the main table is by inserting the date from a userform and then by formatting that cell to just display the month. However, when using advanced filter I use the column headings that I want to filter e.g. department: mens, month: november (worked out using =now() then formatting to just display the month) but when I'm running the filter it's not picking out the information at all.
I think this lies with the way the month is worked out and displayed but I can't figure out another way to do this. Any help is greatly appreciated.
I'm also open to trying a new method of just selecting data for the current month if anyone has a cleaner way, as I'm sure there is one.
You have to use a formula in your criteria to specify what month you want to extract. But it's not terribly intuitive. Take a look at this sample. My starting list is the range A1:B7. My criteria is in range D1:E2. The Department is straightforward; I just entered "3". (Obviously, without the quotes.) But instead of a Month criteria, I added "GetMonth" and entered the formula shown in the formula bar. You can name this whatever you want, but it can't be the same as one of the headers in your source list. (Yeah, I checked.) The formula checks to see if the current month of the date in cell B2 is 12, which is December, and returns TRUE or FALSE. You could use 11 for November. The advanced filter will apply the reference to cell B2 that's in the formula in a relative fashion to all cells in the Month column. And Viola! my output in range A10:B11 is what you'd expect it to be.

Resources