Adding a formula in a self referencing table power query - excel

Hi I'm still new to power query and I'm still trying to understand how it fully works.
The goal that I'm trying to achieve is to create a table that list my employee data (ID, name and location) from a database and adding several columns to the side for another department to fill in the details. Currently I have made this using a self referencing table.
However some of those added columns are using formulas to calculate certain values. I added these formulas in excel, not in power query. The reasoning for this is that the user can see the values update immediately after inputting in the columns. In doing so whenever my query is refreshed, these formulas will get overwritten with values, and when new values are added or changed the totals aren't updated.
I know I can add these formulas in power query, but this will lead to the values not updating automatically, unless it is refreshed after each input. I also tried adding the formulas as string in power query, but it does not change into a formula automatically, it needs to be entered in each cell to calculate.
Current excel setup, in here the first 3 columns are from original database, and the rest are added columns that users are manually inputting through here. And the final column contains the formula to total the values of each row automatically.
Any ideas or tips on how I should change this?
Edit1: By self referencing table I meant something similar to this. Where a column is added to the side of the table and is able to keep track to the corresponding ID.

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.

Get slicer selection of a data table

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]))

Unique Values across multiple columns

I have a spreadsheet that has multiple values in it, but I need to create a formula that would pull the names from the columns without any duplicates. Here's an example spreadsheet:
I would like the result to be like:
So to do it manually, I'm using a SUMIF to search the data for "Walked dog" and add the value.
I'm doing this by manually typing the event names, and if there's one added, I have manually add this instead of something automatically adding that new unique value to the spreadsheet. I've tried SUBTOTAL, SUBPRODUCT, and SUMIF, but they don't seem to do what this spreadsheet requires. Any help would be appreciated.
=SUMIF($C:$F,"Walked dog",$D:$F) is the only function I can get to work correctly, but that requires manual input of the names each time a new event is added.
If you are able to get all your data into one column, you could then use a pivot table. Pivot tables would allow your "Time" column to be grouped and summed up by your "Event" column. As I mentioned, you would need all your "EventN" columns copied into a single "Event" column. You will often need to transpose your data around to make your life easier when using spreadsheets.
Here's the first google result for an example: http://www.excel-easy.com/data-analysis/pivot-tables.html

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