Excel what method use to calculate time and age - excel

I have got a table with 2 columns:
AGE between 10 and 90 lets say :]
and Time (spent on mobiles)
What I need to do is- count how long people spent time on mobiles between 16 and 40.
First part may be seemingly simple because we can count by countif how may people is using mobiles between 16 and 40 but how evaluate spend time on mobiles by the particular age groups.
I will appreciate aaany help
regards

If you need to analyze your data more than creating a static function to count, you may consider using Pivot tables.
Build a simple pivot table with age in rows and time in values. Once this simple pivot table built, you can filter on the rows values, group them together among specific grouping criteria, select specific values by hand, etc.

I like the idea given by Boud of using Pivots but if you specifically want a formula then you can use SumProduct()
=SUMPRODUCT((A2:A13>16)*(A2:A13<40)*(B2:B13))
Do remember to format the cell as [h]:mm:ss since you are adding up times.
SNAPSHOT

You can for example add additional column, with formula like:
=IF ( AND(A1>16, A1<40), B1, 0 )
where A is column with AGE, and B is column with Time, and then simply sum it!

Related

How to resolve Excel IF AND question query formula

Need help with a Excel formula.
I have two sets of data in two tables, with the same number of columns and rows.
One table has data for male, the other one for female.
Each table has a common definer (age). All the other data are different. All data are in numbers. Some are negative.
I aim to use a single cell to get a result coefficient used by a specific equation, and I need to channel the input data by two criteria. One is gender, the other one is age. I am trying the IF AND formula, but it is not working.
Here is an example.
age (D2) coefficient (D2-D4)
Table Female.
18-30 yrs 25
30-60 yrs 35
60-70 yrs 41
So here is the data to process:
D1 F
D2 29
D3 115
(MEANING Gender - female; age 29; weight 115 pounds)
I was trying the IF AND formula
=IF(AND(D1="F";D2>17;D2<30);(D3+H2);IF(AND(D2>=30;D2<60);(D3+H4)))
Now, this works fine when I only calculate the female data, but I can't seem the find the way to include the formula to choose from the MALE table, if the subject is male ("M").
Any help or clues on how to resolve this?
Welcome to stackoverflow. It would be easy to help you if you paste a screenshot of your table etc as it would make us understand your problem clearly.
Anyway, two solution advice from me:
1- you can use nested if operators but not like yours. Before expressing conditions with and operator, add another if to start processing data related to females. Like this: =IF(D1="F";IF(AND(D2>17;D2<30);(D3+H2);IF(AND(D2>=30;D2<60);(D3+H4))).
After processing females, add the same formula strings this time for males. This will solve your puzzle I guess.
2- my second advice would be creating a user-defined function. I often create a user-defined function if my formula gets too long and become hard to read. I strongly recommend you to search for this as it will make you better-understand the logics in excel functions and make you equipped against your puzzles in future.

Formula using Sum product calculate total hours in overlapping date array

Please help,
I want to calculate the actual downtime per each type of equipment and per each type of work order, as shown in the following table sample of the data which extend in real file to 6000 rows:
Data table
, when I use this formula:
{=SUMPRODUCT((COUNTIFS(K2:K6000,"<"&MIN(K2:K6000)+ROW(INDIRECT("1:"&ROUND((MAX(L2:L6000)-MIN(K2:K6000))*1440,0)))/1440-1/2880,L2:L6000,">"&MIN(K2:K6000)+ROW(INDIRECT("1:"&ROUND((MAX(L2:L6000)-MIN(K2:K6000))*1440,0)))/1440-1/2880,G2:G6000,"*"&P3&"*",A2:A6000,"PRMN")>0)+0)/60}
I take a long time to calculate as I use it for 6000 rows with extra 2 criteria, so how I can improve this formula to be faster?
Best Regards,
Mahmoud Hazem

Different aggregation functions for different dimensions in Excel pivot table

Can I define different aggregation methods for subtotals in different dimension in an Excel pivot table?
The following example shows a result I'm trying to obtain. The metric to aggregate is, let's say, lines of code of a software project. The 2 dimensions in question are Date and Organization. In source data, Organization is broken down into 2 columns, Department and Project, while Date is a single column and Excel makes up the Months/Years summaries automatically when making the ODBC data connection.
A metric such as this one should be aggregated differently along the different dimensions. For the Organization dimension, the subtotal for all projects of the department is the SUM, but in the date dimension, the subtotal for all months of the year is the MAX of any given month (or perhaps AVG, or last etc. but certainly not SUM).
I've tried to define the different aggregation methods in Excel in the field settings, but it always selects one or the other method for both dimensions. Is there a way to do it, preferably using standard Pivot Table mechanisms or at worst a UDF in Excel?
What I would do to tackle this problem is to add both aggregation functions: sum and max , then hide ( or shrink a lot ) those columns you do not want to display.
in the above example I shrink columns B,D,F and I because of they has values that are out of scope for your requirements.
The "Total Max of Loc" displays a value consistent with the function expressed throughout the entire column: that is "the maximum number of lines of code reached by each project in each department; this could lead to misunderstandings when we observe the values of the subtotals and grand total; i.e: The "Grand Total - Total Max of Loc" is not the "Total Max of Sum of Loc": in the example, it shows 18 which represents the absolute maximum value of Loc in a Project in each Department; In the same way the Total Max of Loc for Department 2 is 18 and form Department 1 is 12
When requested a different behavior as expressed in comment to this answer, I think we are entering into the strong customizations space and some solution could be found by writing custom macro and by leveraging the getpivotdata function or, if it can be acceptable for your case, simply by the addition of a new column with the max()formula and possibly hiding the column "Total Max of Loc"

Calculate average based on a value column (count) in a pivot table

I'm looking a way to add an extra column in a pivot table that that averages the sum of the count for the months ("Count of records" column) within a time period that is selected (currently 2016 - one month, 2017 - full year, 2018 - 5 month). Every month would have the same number based on the year average, needs to be dynamically changing when selecting different period: full year or for example 4 months. I need the column within the pivot table, so it could be used for a future pivot chart.
I can't simply use average as all my records appear only once and I use Count to aggregate those numbers ("Count of records" column).
My current data looks like this:
The final result should look like this:
I assume that it somehow can be done with the help of "calculated filed" option but I couldn't make it work now.
Greatly appreciate any help!
Using the DataModel (built in to Excel 2013 and later) you can write really cool formulas inside PivotTables called Measures that can do this kind of thing. Take the example below:
As you can see, the Cust Count & Average field gives a count of transactions by month but also gives the average of those monthly readings for the subtotal lines (i.e. the 2017 Total and 2018 Total lines) using the below DAX formula:
=AVERAGEX(SUMMARIZE(Table1,[Customer (Month)],"x",COUNTA(Table1[Customer])),[x])
That just says "Summarize this table by count of the customer field by month, call the resulting summarization field 'x', and then give me the average of that field x".
Because DAX measures are executed within the context of the PivotTable, you get the count that you want for months, and you get the average that you want for the yearly subtotals.
Hard to explain, but demonstrates that DAX can certainly do this for you.
See my answer at the following link for an example of how to add data to the DataModel and how to subsequently write measures:
Using the Excel SMALL function with filtering criteria AND ignoring zeros
I also recommend grabbing yourself a book called Supercharge Excel when you learn to write DAX by Matt Allington, and perhaps even taking his awesome online course, because it covers this kind of thing very well, and will save you significant head-scratching compared to going it alone.

Calculating Percent of Total in Power Pivot Model

I have created a power pivot table as shown in the picture. I want to calculate quarter over quarter sales change. For which I have to divide for example corporate family "Acer" 's sales in 2012Q4 by sum of all the corporate family. I am using calculated measure to do this, but I am not sure what formula I can use.
My need is to create two columns, one for 2012Q4 percent of total and one for 2013Q1 percent of total. Then I will create another measure to find the difference. So the formula for 2012Q4 should be like this 1624442 / (1624442+22449+1200+16123) . Any idea which function can help me do it?
It sounds like you are measuring the change in the percent of total for each corporate family from quarter to quarter. You will need to create 3 calculated measures. I'm not sure what your model looks like so I can't give you the exact formula, but here is the idea.
CurrentQtr%ofTotal:= Divide(Sum('Sales'[Units]),Calculate(Sum('Sales'[Units]), All['Product'[Corporate Family])))
PrevQtr%ofTotal:= DIVIDE(CALCULATE(Sum('Sales'[Units]), DATEADD(DimDate[DateKey], -1, QUARTER)),
CALCULATE(Sum('Sales'[Units]), DATEADD(DimDate[DateKey], -1, QUARTER), All('Product'[Corporate Family]))))
Change%ofTotal:= DIVIDE(([CurrentQtr%ofTotal]-[PrevQtr%ofTotal]),[PrevQtr%ofTotal])
I used the divide function because it handles divide by zero errors. You use the ALL function to remove the filter on the Corporate Family column from the filter context. The Change%ofTotal is just to find the differenc. I'm calculating % change but you may just want to subtract.
Here's the link to a good blog post on time intelligence. And here's one on calculating percent of total.
For percentages please follow the tutorial on the Tech on the Net.
Adding another column where you calculate a difference between two pivot columns will not work - this column is "unpivotable", as it relies on a column defintion. You would need to copy and paste pivot as values to another worksheet and do the extra calculation there.

Resources