count how many got the calculated 100% in Tableau per month - count

I created a calculated field in tableau that computes percentage of a part by the whole
IF SUM([part]) = 0 THEN 1
ELSE SUM([part])/SUM([ALL])
END
I got part of what was needed in my chart. But what I wanted is to count how many got 100% per month.
I thought by creating a calculated field with conditional will do the trick
CASE [percent] WHEN 1 THEN 1 ELSE 0 END
but I ended up with an aggregated summary and not able to count what I needed.
What I would like to create is a bar/line chart that shows the count of 100%s per month

Related

Count total values after CountDistinct

i created a table in which i want to see all the resources that were used on 1 day, for different missions. It's possible that a resource executed more than 1 mission / day. that's why i used an expression with CountDistinct to only show the unique number of resources, used in 1 day for all the missions.
Now as a next step , i want to see what the average number of unique resources is, for a selected time period.
Unfortunately i am not able to use a count or sum expression on the CountDistinct-expression.
If i execute a sum function it gives me the total number of unique values, spread accross the time period, but i want to make a sum of the resources used per day.
fex i have 3 resources , on day 1 i use resource A for 5 missions on day 2 i use resource A & B for 6 missions. so that makes 11 missions on 2 days, and 3 resources ( A + A + B ).
so i want to count the 82+92+100+90+91+92. How do i get the sum of these values ?
any suggestions on how to fix this please?
MANY THANKS!!!!!
Found the solution, created 2 extra datasets to pull the unique values / day.
Added a lookup function in one of the two tablix to compare the values on the same dates ( dates in both datesets ) = > unique values per day. Afterwards made the sum of the values and divided by number of days to get get average unique values / per day.

Adding to a row based upon values from another variable

I'm very new to R and currently working through data from my lab. I have a dataframe with a good amount of variables- two of these variables are Sample and Time. Each sample records a maximum of 10 minutes of observations, then restarts at 0 again for the next sample. I.e., sample 1 correctly displays the timestamps from 0 minutes to 10 minutes. However, upon going above 10 minutes of observations, the Time column will display 0, and the Sample column will display 2. Therefore, each time value in sample 2 observations should be the time displayed plus 10, each time value in sample 3 should be the time displayed plus 20, etc etc. What would be the best way to go about this? Sorry again if I don't have any of the jargon down, I just started learning r.
Without knowing for sure where the column that starts with 9.314... I cannot give an exact answer.
Is there a way for you to add something like this:
df$Time <- df$Time + (df$Sample - 1) * 10
My idea is to take the Time column and add
(1 - 1) * 10 = 0 for Sample 1
(2 - 1) * 10 = 10 for Sample 2
etc

How can I can aggregate by group over an aggregate in Tableau?

I'm trying to visualize the median profit as a proportion of sales for each day of the week. My data looks like this:
Date Category Profit Sales State
1/1 Book 3 6 NY
1/1 Toys 12 30 CA
1/2 Games 9 20 NY
1/2 Books 5 10 WA
I've created a calculated field "Profit_Prop" as SUM([Profit])/SUM([Sales]). I want to display the median daily value of profit_prop for Mondays, Tuesdays, etc.
I can kind of do this as a boxplot by adding WEEKDAY(Date) to Columns and Profit_Prop to Rows, then adding Date to Detail and changing granularity to Exact Date. But I just want to display the median without displaying a data point for each day.
I tried making another calculated field with MEDIAN([Profit_prop]), but I get "argument to MEDIAN is already an aggregation and cannot be further aggregated."
Remove date from the level of detail.
Create calculated field like below and use it instead of Profit prop
median(
{ INCLUDE [Date]:
[Profit_Prop]
}
)
Let me know how it goes.
When you are doing a calculation on a calculated field normal median function doesn't work instead you need to use the Table calculations.
Taking data from your example, create a formula. Use below code:
Create a calculated field and paste below code:
WINDOW_MEDIAN([Calculation1],FIRST(),LAST())
Set the computation to Table Down

Tableau - Average of Ranking based on Average

For a certain data range, for a specific dimension, I need to calculate the average value of a daily rank based on the average value.
First of all this is the starting point:
This is quite simple and for each day and category I get the AVG(value) and the Ranke based on that AVG(Value) computed using Category.
Now what I need is "just" a table with one row for each Category with the average value of that rank for the overall period.
Something like this:
Category Global Rank
A (blue) 1,6 (1+3+1+1+1+3)/6
B (orange) 2,3 (3+2+3+2+2+2)/6
C (red) 2,0 (2+1+2+3+3+1)/6
I tried using the LOD but it's not possble using rank table calculation inside them so I'm wondering if I'm missing anything or if it's even possible in Tableau.
Please find attached the twbx with the raw data here:
Any Help would be appreciated.

Moving average with dynamic window

I'm trying to add a new column to my data table that contains the average of some of the following rows. How many rows to be selected for the average however depends on the time stamp of the rows.
Here is some test data:
DT<-data.table(Weekstart=c(1,2,2,3,3,4,5,5,6,6,7,7,8,8,9,9),Art=c("a","b","a","b","a","a","a","b","b","a","b","a","b","a","b","a"),Demand=c(1:16))
I want to add a column with the mean of all demands, which occured in the weeks ("Weekstart") up to three weeks before the respective week (grouped by Art, excluding the actual week).
With rollapply from zoo-library, it works like this:
setorder(DT,-Weekstart)
DT[,RollMean:=rollapply(Demand,width=list(1:3),partial=TRUE,FUN=mean,align="left",fill=NA),.(Art)]
The problem however is, some data is missing. In the example, the data for the Art b lack the week no 4, there is no Demand in week 4. As I want the average of the three prior weeks, not the three prior rows, the average is wrong. Instead, the result for Art b for week 6 should look like this:
DT[Art=="b"&Weekstart==6,RollMean:=6]
(6 instead of 14/3, because only Week 5 and Week 3 count: (8+4)/2)
Here is what I tired so far:
It would be possible to loop through the minima of the week of the following rows in order to create a vector that defines for each row, how wide the 'width' should be (the new column 'rollwidth'):
i<-3
DT[,rollwidth:=Weekstart-rollapply(Weekstart,width=list(1:3),partial=TRUE,FUN=min,align="left",fill=1),.(Art)]
while (max(DT[,Weekstart-rollapply(Weekstart,width=list(1:i),partial=TRUE,FUN=min,align="left",fill=NA),.(Art)][,V1],na.rm=TRUE)>3) {
i<-i-1
DT[rollwidth>3,rollwidth:=i]
}
But that seems very unprofessional (excuse my poor skills). And, unfortunately, the rollapply with width and rollwidth doesnt work as intended (produces warnings as 'rollwidth' is considered as all the rollwidths in the table):
DT[,RollMean2:=rollapply(Demand,width=list(1:rollwidth),partial=TRUE,FUN=mean,align="left",fill=NA),.(Art)]
What does work is
DT[,RollMean3:=rollapply(Demand,width=rollwidth,partial=TRUE,FUN=mean,align="left",fill=NA),.(Art)]
but then again, the average includes the actual week (not what I want).
Does anybody know how to apply a criterion (i.e. the difference in the weeks shall be <= 3) instead of a number of rows to the argument width?
Any suggestions are appreciated!

Resources