Can I identify calculated formula columns in power query source tables - excel

I have a table that has some columns that are the result of a [power] query which has the key fields, some columns that are intended for manual data entry and some that are formula columns.
My problem is that when I refresh the query columns the manual input data associated with specific query rows don't remain on the same row.
To overcome this I use a query that first extracts the manual input data in the existing table together with the key fields, perform the new query and then do a table join at the end of the query to get the input data back in the correct record. (any input on alternative solutions welcome...)
For tables with no formula columns I could identify the manual input fields automatically using:
List.Difference(Table.ColumnNames(Current_Source_Table), Table.ColumnNames(Pre-Join_Query_Result)).
However, this would also pick up the calculated columns with excel formulas in. How to a distinguish these formula columns to exclude them? Preferably without having a naming convention that allows identification.
Many thanks,
Joe

Excel.CurrentWorkbook does not have information on where columns get their values from, so outside of naming conventions or other potential tricks I don't know, it is not possible to distinguish them.

Related

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

Merging Two Columns in Pivot Table

I am trying to reformat my pivot table. Currently, there are two columns called closed and completed, which essentially represent the same thing. I would like to merge these two columns together. How can I do this?
If you're working with an external datasource (SQL or Access data), this page walks you through how to do it.
http://answers.microsoft.com/en-us/office/forum/office_2010-excel/merge-two-field-sources-in-one-pivot-table-column/934518fe-5e91-47db-95d2-c5d1b4e31082
If you're using internal excel data ranges, you'll need to concatenate the columns first, then bring the concatenated column into your Pivot table.
ie. dataset is A1:G50, columns to combine are F & G. In cell H1, type =f1&g1 hit enter, and use the fill anchor (bottom right of cell) to fill down. Now create your Pivot Table with A1:H50, and just ignore columns F & G.
If the two fields columns represent the same thing, consider whether you can use just one of the fields in your report.
Let's say for your completed tasks field Closed says "Yes" and field Completed says either "Done" or "True".
If you concatenate the two fields' values you'll have PivotItems: "Yes-Done" and "Yes-True" etc..."
If it's necessary to report all those combinations separately, then my suggestion to use one field isn't a good fit.
If those combinations all have the same meaning, then you could keep it simple and just use one field.

Retrieving multiple rows from multiple sheets

I would like to know the best way to approach this problem. I want to search multiple sheets of data based on customerid and retrieve data from each sheet such as customer address(es), customer order(s), customer personal information, etc.
Options off top of my head is...
Filter Pivot Tables by customer but would I do that automatically for all sheets?
vlookup data into one sheet based on customer search term
Is there a way to use an SQL-type command to query data from sheets and display?
I would like to retrieve similar to a SQL query but without use of macros. I don't see a way to retrieve data from these different tables in an automated fashion.
Vlookup basically falls apart the moment you multiple data sets for the same key (for example, 10 order rows for 1 cust_id) unless you make some kind of complex formula to get all of the items and predict how many you need.
I've used 2 solutions for this kind of problem:
1: Several pivot tables on the same sheet, each linked to their respective tables. Unfortunately, the user has to select the same filter for each one as needed. This is still the cleanest solution and I recommend it.
2: Make a translation table (sheet) that glues all of the other tables together.
Each cell just points to the other sheet. Pivot this
For example, if you have table 1 as ID, NAME, ADDRESS and Table 2 as ID, ORDER you might end up with a giant sheet of formulas:
A1 as =Names!A1
A2 as = Names!A2
B1 as =Vlookup(Orders!A1...)
Fill down as needed.. use formulas on this sheet to link the data as needed. You're basically simulating SQL table joins and yes it is a pain but can be done! =) Provided any of this works for your data sets, in theory you could then make 1 large pivot table.

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'.

Excel pivot table using date column to filter results

I have a Pivot Table which I have entered a date field into the Page Fields area to filter the data in the page.
However, I only have the option to select individual dates.
I want to use a date range. How can I do this? Or Can I do this?
Here is a classification by data source of how you can get / use the
Analysis Services
If you are using Analysis Services data, then I think you a breakdown of a date structure (if the dimension and the field is classified as such) by default.
(Hidden) Excel Sheet Data Source
Date Structure breakdowns are not readily available for data from another (usually hidden) sheet in the workbook.
You will have to create additional columns that mark ranges and then you can use it.
For example, lets say you have a SalesDate column. In your source, you should break the column further down so you get the the following columns
SalesDate
SalesYear
SalesQuarter
SalesMonth
SalesWeek
Then you can use these to effectively create ranges. If you have custom ranges you can put them here as well.
External SQL Query
If you are using a SQL Query, you can create computed columns that do these calculations for you. If you have the ability to modify the SQL Query, you can add the columns to the query.
In case you don't have the ability to modify the SQL, you can create Calculated field in the Pivot Table structure.

Resources