Readjust Pivot data using if statement - vba

Currently have data for each month in a separate tab (eg. January data in Tab "January"...) Have pivot tables preformatted in last few tabs. First Tab has a drop down which has all the months. User chooses a month, VBA macro fills pivot table with data from selected month's tab.
If "January" selected from drop down
Then format pivot tables using "January" tab data
Any assistance in how to structure the VBA code would be appreciated. Thank you.

If the data in each of the month sheets have named ranges, you could use the following code once the month is selected on the first tab:
Sheet("YourPivotTableSheet").PivotTables("PivotTable1").changePivotcache
ActiveWorkbook.Pivotcaches
.create(SourceType:=xlDatabase, SourceData:="YourNewNamedRange", Version:=6)

Related

Power BI Query Editor - Filter dates in Dataset based on external input (Excel)

I have a large dataset, with a Date column which goes into past dates and future dates.
I have an Excel table with a specific date (e.g. 01/05/2022). I want to filter out the rows which are in the past vs the input given (01/05/2022) by Excel. In the Power BI Query Editor.
I have only found a way on how to filter by current's date...
Thank you very much,
In Excel, name the input date's cell (Range), such as 'ThruDate' (No spaces, special characters, etc).
From the Data Menu, use 'From Table/Range' to send it into PQ Editor.
In PQ Editor ThruDate query, change Column1 Type to DATE, and Rename the Column 'Date'
In your dataset query, manually filter the date column.
Here's the trick! Edit the code that that step created in the Formula Bar or Advanced Editor.
Replace #date(2022, 1, 5) with ThruDate[Date]{0}
Now, each time you change the Input Date in Range("ThruDate") and Refresh, you'll see only the dates after the input date.

Dynamic column selection in Excel

I have a table in excel with months as columns and couple of rows with data. I would like to add a column on the end of the table that will populate with data from the table as the YTD sum of the month columns. The YTD sum will be based on dynamic selection of the month selected from a list. Have a look at the attached image to see what I mean please, in the example Aug-16 has been selected in column P and the YTD total is returned correctly for this period (this is what I want to happen, but not sure how to?:
enter image description here
The dynamic selector I can do fine (Data validation -> list) but I'm not sure how to populate the column with the correct data, that is YTD for the month selected in the dynamic column added. Not sure if it can be done with MATCH, INDEX etc? I tried, also VLOOKUP, but not working....
One solution is to use this formula using the same parameters as your example image.
=SUM(C3:OFFSET(C3,0,MATCH($P$2,$C$2:$N$2,0)-1))

Google Sheets Query - fill zeros for dates when no data was recorded

How do I change my query in this google sheet so that it generates a table that has a column for every week, even if there is no data for that week? (display 0 in the values fields)
The problem I'm running into is that if there is a week or date with no data, it's not listed. I would like to generate a row/column with 0 for dates without data.
This is how the query is currently written:
=QUERY(A3:D9,"Select A, sum(C) group by A pivot D")
Here's the sheet (hyperlinked so you can see it):
The basic problem you need to solve is to know which data pieces are missing. Do you need the entries for every single day in a given date range? Only weekdays? Only weekdays, except public holidays? etc.
Once you know that, you can insert the missing data in the query itself, by concatenating the source table with literal data as below (where I'm manually adding a combination of Red with Nov 5), or with another query/resultset of another formula that gives you the missing data:
=QUERY({A3:D9; {"Red", date(2018,11,5), 0, weeknum(date(2018,11,5))}},
"Select Col1, sum(Col3) group by Col1 pivot Col4")

How to filter an excel columns which contain date/time as string

I have an excel sheet to filter a Column. The column relates to total experience of a person. The values are like 5years 2Months, 32Years 6Months etc... all the values are in String format. I need the following functionality.
when i enter >5 in a textbox(which i will create in a form), it should display only experience which are less than 5(filtering) . I need an idea how to do this in vba.
Can anyone help..? I just need a way to do this.
Consider the following screenshot. Column a has the unfortunate text with years and months.
Column B splits out the years. Column C splits out the months. Column D has the total number of months for the time frame. With this in place, you can filter by any of the columns using the filter options of the Autofilter built into an Excel table.
The formulas are as follows:
Years: =MID([#total],1,FIND("Years",[#total])-1)+0
Months: =MID(SUBSTITUTE([#total],"Months",""),FIND(" ",[#total])+1,99)+0
Duration in months: =([#years]*12)+[#months]
Now just use the filters in the drop down butttons of the column headers and there is no need for VBA at all.

Microstrategy: With a drop down box Year, how to show values of the selected Year and Previous year in a grid

With a drop down selector 'Year' attribute (All is disabled), how to target a grid report to show values of the selected Year and Previous year?
For example:
User selects year '2012' from the drop down,
the grid should display values of metrics for year 2012 in one column
and 2011 in another column for comparison purpose.
Metric headers are rows and year attribute is column.
Please note, the dataset is created with freeform sql.
Thank you in advance
This can be achieved using transformations in MicroStrategy. Please go through the link for more details.
Link to MicroStrategy Community
However, As you have mentioned that you are using a free form SQL, In this case write another pass of SQL like below and join result of this pass with original pass of SQL using Year column.
Select Fact.Year, Sum(Fact.Metric)
From Fact JOIN Lookup
on (Fact.Year = Lookup.Year - 1)
Group by Fact.Year