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

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).

Related

Multiple Search Key in a Matrix

I'm trying to solve this problem since some days now but it seems I have reached a dead end. Maybe someone would be able to help me.
I have two sheets. The first one contains the list of my clients and their delivery number depending of the weekday.
In my second sheet I would like to get the delivery number of the client (red cells) depending of the weekday I select (yellow cells).
I tried VLOOKUP formula, INDEX/MATCH, QUERY but I wasn't able to find a way to get the delivery number depending of the client's name and the weekday. I think the main issue is that in the first sheet the weekday is a column title.
Maybe the solution is simply to build my tables differently...
Thank you for your help
You can try something like this, assuming A2 and B2 the cells of first name and first day to look:
=INDEX(Sheet1!$1:$1000,MATCH(A2,Sheet1!$A:$A,0),MATCH(B2,Sheet1!$1:$1,0))
Or, if you want this same formula for the full column:
=byrow(A2:A,lambda(each,if(each="","",INDEX(Sheet1!$1:$1000,MATCH(each,Sheet1!$A:$A,0),MATCH(offset(each,0,1),Sheet1!$1:$1,0)))))
Also doable (are perhaps more simply) using a MAP/FILTER; with your 'Caption 1' table in Sheet1!A1:D4 and your 'Caption 2' table at the top-left of Sheet2, the following in Sheet2!C2 gives you the delivery number for a many names/days as you enter in the columns alongside:
=map(A2:A,B2:B,lambda(name,day,ifna(filter(filter(Sheet1!B2:D4,Sheet1!A2:A4=name),Sheet1!B1:D1=day))))
N.B. The IFNA blanks out errors for those rows where a Name/Day pair hasn't been entered yet. Extend the ranges in the filter to suit your real data.
all you need is simple vlookup:
=INDEX(IFNA(VLOOKUP(A9:A11&B9:B11,
SPLIT(FLATTEN(A2:A4&B1:D1&"​​"&B2:D4), "​​"), 2, )))

Automatically update formula after adding columns

My issue has been dealt with in here but I can't think thru and apply it to my formula
How to automatically update formula when inserting columns.
I would really appreciate some help here guys. Thank you!!!
This is the formula I got:
=IF($A$14=NAMES!$W2;$D15;
IF($A$14=NAMES!$W3;$G15;
IF($A$14=NAMES!$W4;$J15;
IF($A$14=NAMES!$W5;$M15;
IF($A$14=NAMES!$W6;$P15;
0)))))
After inserting three more columns it has to go to:
=IF($A$14=NAMES!$W2;$D15;
IF($A$14=NAMES!$W3;$G15;
IF($A$14=NAMES!$W4;$J15;
IF($A$14=NAMES!$W5;$M15;
IF($A$14=NAMES!$W6;$P15;
IF($A$14=NAMES!$W7;$S15;
0))))))
Upon adding 3 more columns to the right, it looks up for the value in $A$14 and if that matches the one in NAMES!$W + i where i is the row incrementing by 1, then it returns a specific column in the same row# 15, be it $D15, $G15, $J15, always jumping three columns.
The 3 columns are automatically inserted via a trigger based on date/time in GAS but I was not able to make the formula automatically update via GAS.
I'm not even sure if this is possible.
Please help!
Thank you!
I write here again because the comment is too short:
You're right!
Here's the link to the Sheet with editor access.
https://docs.google.com/spreadsheets/d/1Qkb96SgZ4dLRBebgxEiNkYiZ4sTtps-ZbBtBtE4J5os/edit?usp=sharing
So basically, whenever a new year is created or 3 more columns are added the formulas in C15, C16 and C17 be updated automatically from
C15 =IF($A$14=Dates!$A2;$D15;IF($A$14=Dates!$A3;$G15;0))
to =IF($A$14=Dates!$A2;$D15;IF($A$14=Dates!$A3;$G15;IF($A$14=Dates!$A3;$J15;0;0)))
C16 =IF($A14=Dates!$A2;$D16+$E15+$B13;IF($A14=Dates!$A3;$G16+$H15;0))
to =IF($A14=Dates!$A2;$D16+$E15+$B13;IF($A14=Dates!$A3;$G16+$H15;IF($A14=Dates!$A3;$J16+$K15;0)))
C17=IF($A14=Dates!$A2;$D17;IF($A14=Dates!$A3;$D17+$G17;0))
to =IF($A14=Dates!$A2;$D17;IF($A14=Dates!$A3;$D17+$G17;IF($A14=Dates!$A3;$D17+$G17+J17;0)))
and so on...
Daniel, I've had a try, and have found a way to get part of your answer. I believe the rest of your problem could be solved in the same way. Look at tab Test-GK in your sample sheet. Your original formula is in C15; mine is in C19.
Both update as you change the value in B14.
I've used a formula to calculate which cell is needed to be used, instead of lots of IF statements. The formula is as follows.
=INDIRECT(ADDRESS(15;(MATCH(A14;Dates!$A$2:$A$15;0))*3+1;4))
This uses MATCH to obtain an 'offset' value for your date range from in your Date values.
Then it multiplies this by 3 to jump to the right column.
So for the first date range in your list, "a 31 de diciembre 2018", MATCH returns "1" (first date range in the list) times 3 plus 1 equals "4", which ADDRESS converts to column "D". The row is always 15 using your sheet.
So ADDRESS(15,1,4) returns D15.
And INDIRECT gets the value of D15.
I think the same principle could be used for the formula in C16. But I'm not as clear what that formula is doing. Does your script put a value into B13?
Let me know if this looks useful.
Update#1. I've got the formula (I think) to replace your formula in C16 as well now. Except for the third term, adding B$13, in only the first case? If necessary, this could be handled with one IF statement, to check if the data range is "a 31 de diciembre 2018".
Let me know how the B13 value is used...
Update #2. Also added a formula to replace your IFs in C17. Effectively the same, but used a CHOOSE function to select which terms get added together, instead of an IF. Maybe a bit clearer to maintain if you add more years to the date range.
Try this formula in C17 - double check the logic.
=CHOOSE(MATCH(A14;Dates!$A$2:$A$15;0); D17; D17+G17; D17+G17+J17; D17+G17+J17+M17; D17+G17+J17+M17+P17; D17+G17+J17+M17+P17+S17; D17+G17+J17+M17+P17+S17+V17; D17+G17+J17+M17+P17+S17+V17+Y17)
It's good to 2025, but if you need another five years or so, you can just make it longer. There is perhaps a way to build it dynamically, but I didn't have the time now for that.

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 :-)

Get conditional mode efficiently in Excel

I am looking to find the mode (most occurrent) value of one column, given another column.
I know how to do it but the calculation takes multiple minutes and can make Excel unresponsive. Therefore I am looking for a better way.
Suppose my data looks like this
group | Level
1 D
1 A
1.1 B
1 C
1 A
1 E
Then I want the output to look like this:
group | LevelMode
1 A
1.1 B
Assuming the data is in the upper left corner of the worksheet, I am now using this formula, which I drag along the C column:
=COUNTIFS(A:A;A2;B:B;B2)/COUNTIF(A:A;A2)
This gives me the ratio of values within the group. Afterwards I remove all that are not above 0.5 as well as duplicates, giving me the mode for each group if it exists.
This formula does exactly what I want, but for about 50000 lines it simply takes too many resources. I expected to find this in the pivot table options, or after a quick search online, but I have not found any way to achieve my goal.
I have decent hardware, a fairly recent version of Excel and would prefer to do this without macro's. However, if macros are required to achieve this then so be it.
Try this:
Step 1.
Create the Pivot Table and place in RowLabels "Group" and under it "Level". Now, place "Level" as count in "Values" field.
Step 2.
See the picture below. Click in the black arrow in the right side of "Level" (you can't see it in the picture but it is supposed to be inside the red circle).
Choose "Values Filters", then "Top 10" and then set the number to 1 (top 1). Done!!
Attention: you need to do step 2 for "Level". If you do the same to "Group" it will not work.
Edit: this is the result and how the Pivot Table should look like.
Now to shape the output to the desired format:
Under PivotTable tools > Design, set the Report Layout to Tabular form
Disable totals and subtotals
Assuming default settings you can now easily copy the list of Groups and LevelModes

Resources