Get slicer selection of a data table - excel

I have been struggling with this issue in the past days and haven't found yet any solution.
I have a simple table (not a pivot table) and some slicers attached to it. I want to 'simply' show selected value/values of the slicer in a cell. It implies of course to make the cell update automatically according to the selection.
Some of the solutions I found suggested using two pivot tables, one main for the regular data and the other hidden to capture the selected filters. The problem is that I am not working with a pivot table, but rather a simple table.
I also tried getting distinct values of the table column, but I couldn't perform it properly without getting the hidden values of the filtered table too.
Is there any way in Excel to do this simply?
Thank you!

You can follow the below steps to achieve your result
You will have to insert a serial number column in your table
After that insert the below formula above the header or anywhere you want to display the selected value
The formula in C2 is
=INDEX(Table1[Data 2],SUBTOTAL(5,Table1[S.No]))

Related

Get data source row number of Pivot Table Active Cell

I need to find a way of determining the row number from the data source table of the selected cell in my pivot table.
The reasoning behind this is that I want to be able to edit/update the values from a UserForm.
My table with the data source is in sheet 1 named Data and my pivot table is in sheet 2, named Project management.
I know I can edit values in a Pivot Table by setting
EnableDataValueEditing = False
..but this does not give me the desired result since my original data remains unchanged and I also have hidden columns that I use for conditional formatting only and it would be a bad user experience to have to unhide the columns every time I need to edit them.
Does anyone have any idea or suggestion as to how I can retrieve the original data row number for a specific cell in my pivot table ?
As an example, the top is my original table and the bottom right is my pivot table. When the cell "Dummy Data" is pressed, I want it to give me the Row number of that data from my original table.
A "bad" workaround would be to use VBA to match the selected cell
value with the data from the table and when the match is found,
retrieve the address but this is not foolproof, the data should be
unique but with more data flowing in over time, this might not be the
case anymore. Therefore I am trying to avoid this method.
PS: if someone could edit my post and embed the image, I would highly
appreciate it.
A pivot table is a report summarizing information from the linked table or query. The only ways you're going to be able to update the information is if you know the row ID/number you want to change or filter the data source down to a point where you can identify it.
If you're going to be keeping and altering records, I'd suggest building a database (Access, for something quick and easy) to enforce some form of integrity and then link your pivot table and form to that database.
EDIT: VLookup or Index(Match(...)) is only going to return the first hit and that may not necessarily be what you want.
I will put my non-orthodox but perfectly functional way of doing it just in case someone is facing a similar issue or until a better way arises.
I have actually added a new column in my data table with the formula
=ROW([#Column1])
This gives me the row number for every entry.
Next I am just adding that column as a row in my pivot table, display in tabular mode to have it's own column and hide it. Therefore when selecting a cell, I am looking in the hidden column for the number and therefore I am getting the source data row number.

Making excel search using one letter in cell

So basically, I have been trying to make excel scan one column and print out the row for cells which have specific letters.
For example I have the following data in my sheet.
What is required is to be have excel search for the values which contain T and I, and then print the new rows. Kind of like separate the two into two different tables, because then so that I can do further analysis on them.
So far I have been trying to use the VLOOKUP() function, but the problem with VLOOKUP() is that excel required a proper match and not just a letter in the cell. I had tried with both FALSE and TRUE. Then instead I tried to use the =INDEX($B$4:$K$9;MATCH($A$17;$A$5:$A$9;0);COLUMN(A4)) to make it work. But that also does not work, since it also requires a full match. Also another problem which I didn't realise before is that how can excel recognise each cell, because I will have different number after the letters everytime and then so how can one make excel not repeat the same row twice?
I have used another approach where I copy the data in a separated sheet and then I simply filter out the Ts and then copy/paste the Is into another sheet and vice versa. it is time consuming and so it would be much better if I can simply copy/paste my new data and it would generate the division on its own.
any suggestions or link would be really helpful.
UPDATE
I had a new idea on how to approach this problem. I was thinking that is it somehow possible to have VBA code running for filtering the data. Is there a way to specify in VBA code to filter the data by "Starts With" and Make the results be printed in another cell block?
Looks simple enough. First step is to make sure you have headers over your data and that it is in proper table format similar to my picture. Then select Data set and press CTRL+T. That should turn you data in to table object with stripes. Use the Formula =LEFT(C2,1) to take out the first letter which will be L or T.
Select the table and press ALT+D+P which will generate a pivot table based off original data set.
Drag the column with the formula I suggested over to the FILTERS area of the pivot table ID column to ROWS and all others to VALUES. Simply refresh and as new data is added you will get new pivot tables. Do not put the pivot tables on top of each other as I did that is only for the picture so you can see it. If you have too many filters to apply you can right click the helper column in the pivot table fields area to produce a slicer which is a button that helps you change the report quickly. Any other questions do ask.

Add column to Excel Power Pivot Table based on slicer seection

I have an Excel Power Pivot Data Model with one table of about 3m entries. In one of my sheets I have multiple slicers that I combine to select entries that fit specific criteria.
I would like to add a column with a value that comes from a cell in the sheet, but only when the entry was part of the selection. For example: when the value in the cell is 1, the selected entries will get "1" in the added column. After that the number in the cell could be set to 2 and a new selection could be made. The new selection will all have "2" in the same added column.
I have been trying to make this work running a macro and DAX, but it can't get it to work. Anyone any ideas?
You can use the VBA I've previously posted at Converting multiple variables into values with excel pivot tables or power pivot to do that. It requires you to make up a 'harvester' PivotTable containing just the columns you want to swap out, so that you can then create a slicer from which to trigger the code.
You can also write a conditional formula in DAX that uses a harvester measure. Something like https://powerpivotpro.com/2012/11/one-slicer-to-control-them-all/ (and plenty of other examples on Google)

GetPivotData with a filter

I want to use several GetPivotData functions, retrieving data from the same Pivot table. I want each of them to retrieve different data based on a filter value.
For instance:
Get Pivot Data for Month:January
Get Pivot Data for Month:February
Where Month is a filter on the Pivot. Is this possible using a formula?
I hope this will solve your problem. Try this workaround from Microsoft:
https://support.microsoft.com/en-us/help/287736/getpivotdata-formula-is-automatically-created-when-you-try-to-create-s
When you change the month, the value changes too. But make sure that there are no hidden items (because if not, you won't get an accurate #/data).
see the screenshot below where the Month to choose is based on a cell reference as an argument in the GETPIVOTDATA formula:
Victor,
The Pivot tables won't work like you intend to. All data that your formula shall retrieve must be visible at the same time. I suggest that you arrange for some space on your worksheet and apply the solution proposed by Scott.
NB: If you want to deal with data added month by month, for example, there is an Pivot table option to automatically add new values to the filter. Then in your formula you can use IFERROR to show blank cells when there is still no data available.
Regards,
+Daniel+

How do I filter dates by a cell formula in an Excel pivot table?

I am attempting to make some reports in Excel using a pivot table of a Sql server view. One of the customer requirements is to be able to filter the reports based on a date range they select, which seems reasonable. The end user process needs to be fairly simple, so my preference is to have a cell for begin date and one for end date and allow the user to
enter these and refresh the table.
There are two problems which I haven't been able to get past:
Selecting a date filter doesn't appear to provide any way for me to reference a cell as a source for the value. I have to put it in at the time.
It seems as if it is only possible to define a date range if I am grouping on the date field. For some of the reports, this violates the specification. The Report Filter section of a pivot table only seems to allow me to filter by individual values rather than a range. This gets unmanageable on real data which might have hundreds of dates to go through.
One thing I have tried is to create an intermediate table without any aggregates columns in a separate sheet in the same workbook, and then filter that. This hid the columns correctly in that intermediate table, but had no effect on the pivot table which derived from it.
Does anyone have ideas for how I can make this work? It seems like a fairly obvious use case - is there something I am missing about how pivot tables are supposed to be used?
The easies thing you can do is changing your pivot table query on the fly.
When the source cell is changed (Worksheet_Changed event), append " AND WhateverDate > '1/1/1111'" to Me.PivotTables("Your pivot").PivotCache.CommandText and refresh the pivot.
I remember I solved a similar requirement some years ago by making the SQL query dynamic (i. e. putting it together as a string in VBA, and using the cells with the range values in the where condition). ant the VBA macor was then called with a button labeled "refresh".
But I am sorry do not have this code available any more, I just remember the general idea.
This has been dead for a while, but I thought I would post a different method. add a formula to the source table that returns a '1' for thing you want, and a '0' for things you don't, and then add a filter in the pivot table that filters only the '1'.

Resources