How to create a dynamic table in Excel? - mysql

I am trying to create a dynamic table - I have tried a Pivot Table, but cannot get it to work. So I thought that maybe it could be done with an IF-statement, but that did not work for me neither.
Basically, I have 2 tables, 1 table containing the information (data source table) and 1 table that should be dynamic according to the data in the first table.
So if I change the data in the E-column, the Fruit table (image below) must be updated accordingly.
So if I write 2 instead of 1 in the count of Apples, then it should create 2 apples under the "Fruit"-column". Data in the remaining columns will be calculated with a formula/fixed data - so that is not important.
I am open to any solutions; formulas, pivot tables, VBA, etc.
Have a nice weekend.
I have both Excel 2010 and 2013.

If you want to repeat some text a number of times you can use a somewhat complicated formula to do it. It relies on there not being duplicate entries in the Fruits table and no entries with 0 count.
Picture of ranges and results
Formulas involved include a starter cell E2 and a repeating entry E3 and copied down. These are actually normal formulas, no array required. Note that I have created a Table for the data which allows me to use named fields to get the whole column.
E2 = INDEX(Table1[Fruits],1)
E3 = IF(
INDEX(Table1[Count],MATCH(E2,Table1[Fruits],0))>COUNTIF($E$2:E2,E2),
E2,
INDEX(Table1[Fruits],MATCH(E2,Table1[Fruits],0)+1))
How it works
This formula relies on checking the number of entries above the current one and comparing to the desired count. Some notes:
The starter cell is needed to get the first result.
After the first cell, it counts how often the value above appears in the total list. This is compared to the desired count. If less than desired, it will repeat the value from above. If greater, it will go to the next item in the list. There is a dual relative/absolute reference in here to count cells above.
Since it goes to the next item in the list, don't put a 0 for a count or it will get included once.
You can copy this down for as many cells as you want. It will #REF! when it runs out of data. You can wrap in an IFERROR(..., "") to make these display pretty.
If the non-0 rule is too much, it can probably be removed with a little effort. If there are duplicates, that will be much harder to deal with.

Related

How to count a range of values in datastudio

I am trying to transform a report that I have made in sheets into the newest datastudio tool. In my sheet, I have a table where there are several columns that holds data related (this is because each row could have more than one value so I used the "split text into columns" function to represent).
What I have is something similar to:
ID
Component
Component 1
Component 2
101
wood
metal
gold
102
metal
copper
103
wood
gold
metal
In my excel, I have a formula to count the time a certain component is shown by using =COUNTIF(<range>,<string>)
Therefore, with the above formula, I have something similar to:
Component
count
wood
2
metal
3
copper
1
gold
2
I want to be able to build the same in datastudio. Turns out that since the components are divided into columns, I can only use one dimension and the result only shows the count of the first column.
I want to know if there is an easy way to accomplish this. My original data source is like this:
ID
Component
101
wood;metal;gold
102
meta;copper
103
wood;gold;metal
Maybe it's easier to work directly with the previous format but again, using the component in this case only counts for the first occurrence and not across the whole string.
For now, the only solution I can think of is splitting the text into rows instead of columns, but that is not feasible achievable using Google Sheets, or at least not that I am aware of.
Could somebody have an idea of how to accomplish this?
Thanks!
Edit
I am adding here the minimal reproducible example. This is the spreadsheet that I have (example) and the current report I am using so far (built-in sheets):
Now, I want to have the same report (plus more things) using datastudio. This is the report example I have in data studio. As you will see the record count for components is not accurate in DataStudio.
Here is a preliminary answer. I'll polish if we like it and delete it otherwise.
Consider the following sheet:
Range A2:B4 contains my data of interest. Rows 7:10 show the results I think you are looking for. The mechanism for creating this is the value of cell A6 which contains:
=ARRAYFORMULA(QUERY(FLATTEN(SPLIT(B2:B4,";")), "SELECT Col1, COUNT(Col1) WHERE Col1 is not null GROUP BY Col1"))
At the highest level, the formula splits each of the delimited text items into their own cell and then flattens all these cells into one column against which we then run a SQL query against the sheet to group and count them.

How can I create a table that uses an equation to average data from another table?

I have a table that contains data from repeated experiments (for example, site A has one sample, and the lab processed the sample three times obtaining slightly different values). I need to average these results in a separate table, but what I have read on the Microsoft support site is that a query that pulls data into another table with a calculated field is not possible on Access.
Can I query multiple data points from one table into a single calculated field in another table? Thank you.
UPDATE
I ended up doing a lot of manual adjustments of the file format to create a calculated field in the existing table that averages each sites data, so my problem is, for my current purposes, solved. However I would still like to understand. Following up with you both, I think the problem was that I had repeated non-unique IDs between rows when I probably should have made data columns with unique variable names so that I could query each variable name for an average.
So, instead of putting each site separately on the y axis, I formatted it by putting the sample number for each site on the x-axis:
I was able to at least create a calculated field using this second format in order to create an average value for each site.
Would have there been a way to write a query using the first method? Luckily, my data set was not at all very hefty, so I could handle a reformat manually, but if the case were with thousands of data entries, I couldn't have done that.
Also, here is the link to the site I mentioned originally https://support.office.com/en-ie/article/add-a-calculated-field-to-a-table-14a60733-2580-48c2-b402-6de54fafbde3.
Thanks all.

SUM function needs automatically to adjust for changes to SQL DB entries

I'm using multiple Calc tables in a single document for ingoing and outgoing bills that are stored in a SQL DB. Table A has ingoing bills and Table B has outgoing bills. For example table A has data from B2-B39 and table B has data from B2-B15. I need the sum function to automatically adjust when data entries are added or subtracted.
I can use =SUM(B2:B39) in tableA.B40 and =SUM(B2:B15) in tableB.B16 to get the sums of the current data, at the end of the data entries. However, when the DB changes, for example Table A has data from B2-B44, I end up missing five entries. To further complicate things, I have Table C, where I evaluate the net income. For example in Table C I use tableB.B16-tableA.B40. When the number of entries in tables A and B change the function in Table C no longer works.
I need SUM in multiple tables to automatically adjust its position based on how many rows of data are found in the DB.
Maybe there is something about your layout that you have not mentioned but a solution would seem to be to apply whole column references (eg =SUM(B:B)), or if you must have the total in the same column move it to the top and sum like so:
=SUM(B2:B1048576)
Otherwise try something like LibreOffice Basic and search for the first empty cell in the column to put the formula in.

SSRS column group displays data on unique rows

I have a data set where i'm using a table to display Name, Radio #, and Unit # information in SSRS tablix. As some of the groups have 60+ members, i thought it would be better to expand the tables into 4 columns repeating those detail fields instead of displaying a 3 page long skinny table. In the SQL i used a row count%4 function to assign a "position" number 0-3 for each name. If i create a table with the detail members above and then add a parent column group on position, i get the tables repeated as i want but each name/radio/unit appears on a unique row. I've tried several different ways of grouping rows/columns but always seem to get this staggered table (with only name/radio to make it easier to digest): sample_pic
Sorry if this is a duplicate. I've really searched quite a bit before putting this in but it's probably the case that if i knew what to search, i wouldn't be putting this question in. So if you'd rather tell me what to search i can do that too. :)
SSRS will display a row in the table for each row returned from the dataset, this is normal behaviour for data to display.
One way to get what you want is to create a query which has all the information form your column headings in one row, probably with a pivot or similar.
Or you could just display your columns in separate tables.

Fill cells depending of dataset values

I have a table like this one below. I have one dataset which returns data like this:
Day Hour Title
-----------------------
Monday 2 Title1
Monday 4 Title2
Friday 5 Title3
.
.
.
.
I need to fill the table depends of values in dataset, ie. first row of dataset will take place where first column(Monday) intersect with second row(2.).
How can I do this task.
I am using SSRS 2008.
Use a matrix.
See here also see this similar question
EDIT: This interesting blog post shows how you can build a calendar in SSRS.
Problem solved
First, on database, I am creating two Common Table Expression or CTE, for days and hours respectively. Then, I am make CROSS JOIN between them, and thus form a one relation. Then I make left join with rest of needed tables, to get values (if exist, of course) for each combination from CROSS JOIN.
On reports, I am create matrix, related to dataset, which is linked with previously created stored procedure. For column group, I choose days, for row group I choose hours, on intersect I place specific values.
Really simple, but great job is done with cross joined two CTE's.