What is the equivalent of Excel's Subtotal in Power Pivot? - powerpivot

Is there a way to count the total number of rows returned in a filtered table in Power Pivot? I tried populating a column with 1 or 0 and used SUM. But it returned the number of rows in the original table and not in the filtered.

if you want to count rows, you can use this formula
Myformula:=Countrows(mytable)

Related

How to add/subtract from next row in SQL

How do I take the following table:
and make it so the Amount 3 column subtracts from the remaining amount in the row above?
Basically, I know I can do Amount 1 - Amount 2 to get the difference, but if I have multiple values I am trying to subtract from an original value, how can I write a SQL function so the Amount 2 column is added to the cumulative remaining balance in the above Amount 3 column to have a new cumulative remaining amount?
I'm assuming it's some sort of LAG function, but I still need help.

In MongoDB, What is the time complexity of this query?

There is a table of M rows, with a column which records the date and time the row was updated and a numeric column to record the SCORE of this row.
QUERY:
Find the X most recently updated rows and compute the average SCORE.
EDITED:
Further, let's break it up into 2 querys:
Find the X most recently updated rows.
Compute the average SCORE of the rows returned in 1.
What is the time-complexity of query 1 and query 2?

SUM results is multiplying by number of rows

I'm creating a crystal report from several tables.
One table has fields that I want to have sum totals on, but these sum fields are being distorted by number of rows from another table. There are no fields other than DocEntry that I can link with between the two tables.
Here, total bales is repeating 4 times:
If I sum the field total bales, instead of showing 12 the result is 48:
Please assist.
Insert a Group on DocEntry.
Add a Running Total that sums Bales but evaluates only on change of group.

Is it possible to create more rows than original data using GROUPBY and COUNT(*)?

I have the following query:
SELECT "domain", site_domain, pageurl, count (*) FROM impressions WHERE imp_date > '20150718' AND insertion_order_id = '227363'
GROUP BY 1,2,3
It was an incorrectly conceived query this I understand, but it took over 30 minutes to run, while just pulling the data without a count and groupby took just 20 seconds.
My question being is it possible that there are more rows created than the original data set?
Thanks!
The only time that an aggregation query will return more rows than in the original data set is when two conditions are true:
There are no matching rows in the query.
There is no group by.
In this case, the aggregation query returns one row; without the aggregation you would have no rows.
Otherwise, GROUP BY combines rows together, so the result cannot be larger than the original data.
When you are comparing time spent for returning a result set, you need to distinguish between time to first row and time to last row. When you execute a simple SELECT, you are inclined to measure the time to the first row returned. However, a group by needs to process all the data before returning any rows (under most circumstances). Hence, it would be better to compare the time to the last row returned by the simple query.

Calculating a percentage of two "Counts" in SQL in Microsoft Access 2010

I have a Microsoft Access 2010 database of thyroid surgeries. I have a query that counts the number of surgeries in the entire database. I have a second query that counts the number of surgeries performed between certain dates. I created a new query using SQL to calculate the percentage of surgeries in that date range (a percentage of the total surgery number). Here is the code:
SELECT
((select count(ThyroidSurgeryType)
from [Thyroid Surgeries]
HAVING ([Thyroid Surgeries].SurgeryDate) Between #1/1/2011# And #12/31/2012#)/(select count(ThyroidSurgeryType)
from [Thyroid Surgeries])) AS Percentage
FROM [Thyroid Surgeries];
I get .33 (I then set the row format to percentage to get 33%), but I get 6 rows of 33% as opposed to just one. Why is it displaying this way? Thanks
The way you're using inline queries, you're executing the same query per row of the outer query. So if your table has six rows, you'd be executing it six time (and getting the same result for each query, naturally). You can simplify things by removing the outer query and using an iif expression:
SELECT SUM (IIF (SurgeryDate Between #1/1/2011# And #12/31/2012#, 1, 0)) /
COUNT(ThyroidSurgeryType) AS Percentage
FROM [Thyroid Surgeries];