Counting gone horribly wrong - visual-studio

I'm trying to create a rdlc report in Visual Studio 2008 and I'm having a bit of trouble with the totals at the end.
I have a string field called "Reward" that displays either 1, 2, 3 or B. At the end of the report, I need to count up how many total records, how many "B"s and how many are not "B"s. So my inclination is to have three fields at the bottom as such:
Total =COUNT(IIF(Fields!Reward.Value > "a",1,0))
Bs =COUNT(IIF(Fields!Reward.Value = "B",1,0))
Non-Bs =COUNT(IIF(Fields!Reward.Value <> "B",1,0))
But all three end up equaling the same (the total record count). I thought that seemed weird so I tried data that doesn't appear in that column at all such as
=COUNT(IIF(Fields!Reward.Value = "4",1,0))
and I still get the same number. Any ideas what I'm doing wrong?

Perhaps you want SUM instead of COUNT?
If you're returning value 0 or 1 from your IIF, you're actually just counting how many values are being returned, no matter the numeric value within.
Change the Bs and Non-Bs to SUM, and you'll get the results you're looking for.

Related

Reset count after a new month starts

I'm adding data to a spreadsheet and I want to do basic tasks programmatically.
Every time I add a date like 03/01/2022 the month cells updates to "March" with
ARRAYFORMULA(IF(E2:E = "","", TEXT(E2:E,"mmmm")))
So, I'm counting the entries per month like this:
I created a formula to make a sequence, but it'll go infinitely as per the number of rows, I'd like to reset the count when the Month cell is different than the previous one.
=SEQUENCE(ROWS(B2:B))
David, I assume "Month" is in column B and you want the sequence in column A under "No."
Try using this formula in A2:
=arrayformula(if(B2:B="",,countifs(B2:B,B2:B,row(B2:B),"<="&row(B2:B))))
Briefly:
uses the arrayformula so you don't have to copy down the formula
if(B2:B="",, takes care of any blanks
countifs() along with row() does the rest of the magic.
to see the role of row(), try using just countif(B2:B, B2:B). This will give the total number of occurrences of "January. "February", etc.
row() combined with "<="&row() makes sure that the formula counts occurrences above the current row only.
Watch out for year change. All "January" values across different years will be added to the sequence.
Good luck.

Google Sheets sum mapped text values by group

I'm looking to count the groups that have at least one occurrence of specific text values in a column. E.g., if any of term_01, term_02, or term_03 are in column B, for 1 or more records associated with a specific value in column A, count 1.
This is not too difficult with a helper column, but I'm trying to do it in one go, with a single formula.
Another way to think about this is that unless every record for a given column A value (e.g. group_01) has a value of term_04 in column B, add 1 to the value displayed in cell I1.
Solution with a helper column:
The helper can be created with an array formula:
Unfortunately, replacing the [sum_range] in SUMIF() with an array fails with "Error: Argument must be a range"
Is there a way to pass an array of values to SUMIF() instead of a range? Am I going about solving this problem the wrong way?
I would still be interested to know if there's a general solution to the question asked in the title, but I solved this specific problem with a slightly different approach.
If the number of records with a term_04 value equals the total number of records for that group, assign 0, otherwise assign 1, and sum the result.
=ArrayFormula(SUM(IF(COUNTIFS($D$3:$D$10, UNIQUE(D3:D10), $E$3:$E$10, $A$6)=(COUNTIF($D$3:$D$10, UNIQUE(D3:D10))), 0, 1)))

It is possible to sort by "valid" percentage in my data?

Using Tableau, I have arranged some data in a 100.00% stacked bar:
I want to sort the data descending (largest to smallest) by Valid component type (green) - is this possbile?
UPDATE (26th July 2017)
merawalaid's answer ALMOST worked; I followed the steps, adjusted the code to match my specific project, and it resulted in this:
As you can see, it is somewhat sorted, but not quite as it should be (for example, the fourth and sixth rows are featured too high in the chart.
Is there something that might be wrong that I have missed here?
I was able to do this: You can download my workbook here.
Be advised though, I feel there would probably be a simpler way out there to do this.
What I did was to create 2 calculated fields.
'ValidComponentCount': IF ([Component Type]='Valid Component') THEN 1 ELSE 0 END
'% of Valid': {FIXED [Rootname] : SUM([validCount])/COUNT([Number of Records])}
Then sorted the 'Rootname' column based on descending value of the 2nd calculated field (% of Valid).

How can I get the values in the Matrix on my SSRS report to repeat?

I know there must be a simple answer to this, but I can't find it.
I have added a couple of textboxes to a Matrix in a BIDS/SSRS report. I've given these textboxes values such as:
=Fields!WEEK1USAGE.Value
It works (after a fashion); when I run the report (either on the Preview tab, or on the Report Server site) I see the first corresponding data value on the report - but only one.
I would think that once a value has been assigned via expressions such as "=Fields!WEEK1USAGE.Value", each value would display (rows would automatically be added).
There must be some property on the Matrix or the textbox that specified this, but I can't see what it might be.
Here is how my report looks (very minimalistic, so far) in the Layout pane:
...and after running, on the Preview tab:
Obviously, I want the report to display as many rows as necessary, not just one. The textboxes do have a "RepeatWith" property, but there description doesn't sound interesting/useful/promising.
I don't see any property on the Matrix control that looks right, either.
I thought maybe the designer was only showing one row of values, and ran the report on the server, too, but there also it just shows the two values.
So what do I need to do to get all the data for a provided field?
Matrices are for display of grouped data and summary information, usually in a horizontally expanding pivot table type of format. Is a matrix really what you are after? Looking at your expression you have =Fields!Week1Usage.Value but in a matrix what I expect to see would be at least =Sum(Fields!Week1Usage.Value) or even better just =Sum(Fields!Usage.Value). Then you would have ProactDescription as your row group and the week as your column group and it would all just work out everything for you, grouping and summing by Proact vertically and expanding the weeks out horizontally.
What seems to be happening is that you have no grouping on rows or columns and no aggregation so it is falling back to the default display which is effectively the First function - it displays the first row of data and as far as the matrix is concerned it has done its job because there is no grouping.
Without knowing your problem or data, I'll make up a scenario that might be what you are doing and discuss how the matrix does the heavy lifting to solve that problem. Let's say you have usage data for multiple Proacts. Each time one is used you record the usage amount and the date and time it is used. It could be used multiple times per day but certainly multiple times in a week. So you might be able to get the times each Proact is used from a table like so:
SELECT ProactDescription, TimeUsed, Usage
FROM ProactUsage
ORDER BY ProactDescription, TimeUsed
In your report you want to show the total weekly usage for each Proact over multiple weeks. Something like this:
Proact Week1 Week2 Week3 ...
Description Usage Usage Usage ...
--------------------------------------------
Anise, Fennel 1 CT 20.00 22.50 16.35 ...
St John's Wort 15.20 33.90 28.25 ...
...
and so on. Using a dataset based on the SQL above we create a matrix and in the row group properties we group on =Fields!ProactDescription.Value and in the column group properties we group on a week expression like =DateDiff(DateInterval.Week, Fields!TimeUsed.Value, Today) and then in the intersection of the row and column we put =Sum(Fields!Usage.Value). To display the header of the column nicely put an expression like
="Week " & DateDiff(DateInterval.Week, Fields!TimeUsed.Value, Today)
The matrix automatically does all the summing by week and product and expands the weeks horizontally for as many as you are reporting. For bonus points you can also put totaling at the end of the columns and the rows to show the total use of that Proact for the period (row total) and total use of all Proacts in that week (column total).

Can I compare values in the same column in adjacent rows in PowerPivot?

I have a PowerPivot table for which I need to be able to determine how long an item was in an Error state. My data set looks something like this:
What I need to be able to do is to look at the values in the ID and State columns, and see if the value in the previous row is ERROR in the State column, and the same in the ID column. If it is, I then need to calculate the difference between the Changed Date values in those two rows.
So, for example, when I got to row 4, I would see that the value in the State column for Row 3, the previous row, is ERROR, and that the value in the ID column in the previous row is the same as the current row, so I would then calculate the difference between the Changed Date values in Row 3 and Row 4 (I don't care about the values in any of the other columns for this particular requirement).
Is there a way to do this in PowerPivot? I've done a fair amount of Internet searching, and it looks like if it can be done, it would use the EARLIER or EARLIEST DAX functions, but I can't find anything that tells me how, or even if, this can be done.
Thanks.
Chris,
I have had similar requirements many times and after a really long time of trial-and-error, I finally understood how EARLIER works. It can be very powerful, but also very slow so always check for the performance of your calculations.
To answer your question, you will need to create 4 calculated columns:
1) Item Rank - used for ranking the issues with same Item ID
=COUNTROWS(FILTER('ID', EARLIER([Item ID]) = [Item ID] && EARLIER([Date]) >= [Date]))
2) Follows Error - to easily find issue that follows EROR issue
=IF([State] = "EROR",[Item Rank]+1)
3) Time of Following Issue - simple lookup so that you can calculate the different
=IF([Follows Error]>0,
LOOKUPVALUE([Date], [User], [User], [Item Rank], [Follows Error]),
BLANK()
)
4) Time Diff - calculation of time different for the specific issue
=IF([State]="EROR",
DAY([Time of Following Issue])-DAY([Date]),
BLANK()
)
With those calculated columns, you can then easily create a powerpivot table, drag State and Item Id onto the ROWS pane and then simply add Time Diff to Values. You will get an overview of issues that contain string "EROR" issue and the time it took to resolve them.
This is what it looks like in PowerPivot window:
And the resulting Pivot table:
You can download my Excel file here (2013).
As I mentioned, be careful with the performance as the calculated columns with nested EARLIER and IF conditions might be a bit too performance-demanding. If there is a smarter way, I would be very happy to see it, but for now this works for me just fine.
Also, keep in mind that all calculated columns could be nested into 1, but I kept them separated to make it easier to understand the formulas.
Hope this helps :-)

Resources