How to get the counts/frequencies of values in a table? - excel

I have the problem that I need to get the number of occurences / the counts or frequencies of values in a table. However, I cannot give the categories before, so in opposite to countif I cannot specify a specific value, as this needs to be done from the table. I have a whole table, not just a column. The picture shows a reduced example:
The result I need would look like the following (I counted manually, hope I did not do a mistake):
It is not needed to calculate empty cells.
For the starting point I am ok with not specifiying if there is a difference between lowercase and uppercase (so L and l for example). This can be calculated separately or as the same. Later on it would be good to be able to choose this as an option. (I could use lowercase function and refer to this column and fill another column with the values, however the original data is way too large.). My problem is now that I am not able to do this "simple" task. I found a solution for a single column, using a matrix function with countif:
{=countif(A21:A27;A21:A27)}
This does not work for a whole table. My original data is too large to do any task manually and repeat this for each column or rearrange the data manually from table to one single column.
Unfortunately I am limited to Excel and/or Excel VBA. I cannot use any other tool. I am happy with an excel solution, if there is a way to do it in VBA I am also very ok with it, however for this I cannot give a proof that I tried it, because I don't have an idea how to program this and I am not advanced enough in coding VBA.

Through PowerQuery
Sample data:
My Excel is in Dutch so excuse me for making some translation errors. It should still point you in the right direction:
1: Select all data > Data Tab > Transform > From Table/Range > Choose No headers
2: In PQ select all 4 columns > Transform Tab > Unpivot all columns
3: Select value column > Transform Tab > Pivot Table > Ok
4: Select all columns > Transform Tab > Unpivot all columns again
5: Exit PowerQuery and confirm to save your edition.
Result:
Will exclude empty cells
Will distinguish between upper and lower case

Analyzing this data is easiest if it is in one column. You can use Power Query (Get & Transform) for that. Load the data into the Power Query Editor, keep only column 1. Repeat and keep only column 2, repeat for columns 3 and 4.
Next, append the columns, so you have one column of data.
Now you can either load this data into the data model and THEN it's easy to build a pivot table. Blank cells can be removed in the Power Query or by filtering the pivot table.

Related

Quick reshaping of table in Excel

I'm new to using Excel/DAX.
Just wondering if there would be a quicker way to format the table
What I'm trying to achieve, is getting the above table to be formatted the same as below
Notice how in the lower table there is only 1 column for the year. I understand that this creates duplications of the countries in the first column
Any advice would really help.
Load the table into PowerQuery
Select the first 2 columns
In the Transform tab select from Unpivot other columns
There you go!
Btw, it's a typical ETL step (hence PowerQuery) called stacking a table from wide to long.

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.

How do i use a lookup in excel to return a value from a third column, if criteria are met in 2 other columns

I have a dataset which has columns as follows. It shows me the number of people (in the time columns) that are in the room (resource) on date.
Sample Dataset:
I am attempting to return the following.
Sample Result:
Essentially, im trying to search my dataset, and return the number of people in each room, at each time and date, in a more digestible manner.
Apologies if i havent explained myself correctly, and i havent really worked out how to use this forum properly yet, but i'm hoping to use the collective to help with this problem. I'm not an excel newbie, but i can't seem to get the right mix of match/index/v/hlookups to do what i need! Thanks :)
Ok, so updating based on NightCrawler's assistance, still getting random errors at 1 and 4pm! any tips?
I achieved your desired result using this formula. I added another column to get correct dates in each row because i did not want to deal with merged cells (see image).
=SUMIFS(OFFSET($C$2:$C$7,0,MATCH($D11,$C$1:$L$1,0)-1),$A$2:$A$7,$B11,$B$2:$B$7,E$10)
Drag the formula to all cells
Here is another method you could use
Select your data. Goto Data Tab. Under Get & Transform, click From Table. In the pop-up check My Table has headers -> OK
A window(Query Editor) will pop-up.
Select your time columns and in the transform tab click Unpivot Columns. This is what you will get
Notice that the time column is now renamed and there is a new colunm "value".Now select your resource column and click on Pivot column (Transform tab). For Values Column, choose Value(the new column that was added) . In advanced options, make sure "Sum" is selected.
Click OK. you should have your result. In the Home tab click close and Load.
The rows may not be in the correct order, coz you are using it as a string. You may use numbers for better sorting.

OR filter between table columns

Is there a way to filter Excel tables similar to how Access queries can filter fields with OR operators?
E.g. I have the following table:
I want to list all items with the Messis aspect. In Access, one would make a query with Messis OR Messis OR Messis.. each in the following line or with OR in between. I would like to do something similar in Excel...
If I understand your question correctly, you want to find the row(s) where text X appears in any one of several columns. To do this, consider adding a column that is the concatenation of each column. Then use the column filter to select rows that contain text X.
An example:
For Column 6:
Results in:
Alternate answer
If, on the other hand, you want the OR statement for a single column, you can use the OR feature of the AutoFilter. If that doesn't appeal to you, you can use add a range outside of the table that includes has the text of a column in its first cell. Put the possible text options in the cells immediately below. Here's a picture:
Then, with the cursor in your table, click on Data, Advanced and complete the dialog box as shown.
Click on OK to see:

Is there an easy way to reformat a poorly-formatted tree to a two-column table?

I have a table representing a series of components and their subcomponents, and the subcomponents' respective subcomponents, and so on. It currently looks like a tree (one-to-many relations), but it could change at some point to resemble a graph (many-to-many relations) instead. Unfortunately, it was poorly formatted by its author, and looks something like this:
The above format is poor because there is a lot of data duplication and it is limited to a set number (4) of tiers. I would instead prefer if it looked something like this:
The above format is nice because there is very little data duplication, and it is not limited to a set number of tiers.
In case there is any confusion about what the tables represent, here is a graphical representation of the data:
It is simple enough to convert from the poor format to the nice format, but there are hundreds of root components, and manual data entry would be far too time-consuming and tedious.
I suspect this problem is unique and I am prepared to write some VBA code myself to parse the table into the nice format, but I thought I'd make sure that this wasn't a common problem with a pre-rolled solution before I rolled my own.
Is there a technical term to describe the poor formatting in the first table? Is there an easier way to reformat the data than to write a VBA macro?
This may be a complete aberration but it works for your sample (and at the moment I don’t have time to break it!)
Add an index (and a label for it) and reverse pivot (eg see An excel formula to find a row/column index in array).
Instead of drilling down on the Grand Totals intercept, drill down on each of the totals for the Tiers.
Reassemble the tables side by side, delete all columns except the Value ones and copy table to another area with Paste Special Values. Remove Duplicates on the range. Every time the value in the column immediately to the right does not change, delete and shift the values in the cells to the left. Reorder the columns right to left.
I copied each pair of adjacent columns in the Tier table (Tier 1 & Tier 2, Tier 2 & Tier 3, Tier 3 & Tier 4) and pasted them stacked vertically into a single pair of columns (Subcomponent & Component).
Next, I removed duplicates by selecting both of my new columns and clicking Remove Duplicates in the Data ribbon tab.
Next, I had to remove all rows which contained a blank cell in the Subcomponent column. To do this, I selected both columns again and filtered the data by clicking Filter in the Data ribbon tab. I selected (Blanks) in the Filter menu on the Subcomponent column and deleted all visible rows. I removed the filer by selecting (Select All) in the filter menu.
The resulting table contained many blank rows, so again I removed duplicates, and then manually shifted the data up one row to displace the one remaining blank row.
In the end, it took about a half hour, which is probably less time than it would have taken me to code a macro, and definitely less time than manual data entry.

Resources