I am trying to work out the ranking of top 3 users at different organisations and have the data presented horizontally for each user so it can be inputted into our email system to personalise emails.
I am able to create a ranking vertically but I am not sure how to get the formula to rank based on organisation and return value across.
Here is what I need to have in the end:
Name Organisation Usage First Second Third
User 1 Organisation 1 8 User 3 User 5 User 2
User 2 Organisation 1 10 User 3 User 5 User 2
User 3 Organisation 1 222 User 3 User 5 User 2
User 4 Organisation 1 1 User 3 User 5 User 2
User 5 Organisation 1 14 User 3 User 5 User 2
User 1 Organisation 2 215 User 4 User 1 User 5
User 2 Organisation 2 18 User 4 User 1 User 5
User 3 Organisation 2 12 User 4 User 1 User 5
User 4 Organisation 2 310 User 4 User 1 User 5
User 5 Organisation 2 161 User 4 User 1 User 5
I can return a ranking vertically one organisation at a time using
=INDEX($A$2:$A$6,MATCH(1,INDEX(($C$2:$C$6=LARGE($C$2:$C$6,ROWS(H$1:H1)))*(COUNTIF(H$1:H1,$A$2:$A$6)=0),),0))
If someone could help me run this formula based on each organisation and horizontally that would be fantastic!
Thanks,
Sarah.
Non-Empty Usage Solution:
Assuming your data starts in A1 Like so:
A B C D E F
---------------------------------------------------------
1 | Name Organisation Usage First Second Third
2 | User 1 Organisation 1 8 User 3 User 5 User 2
3 | User 2 Organisation 1 10 User 3 User 5 User 2
4 | User 3 Organisation 1 222 User 3 User 5 User 2
5 | User 4 Organisation 1 1 User 3 User 5 User 2
6 | User 5 Organisation 1 14 User 3 User 5 User 2
7 | User 1 Organisation 2 215 User 4 User 1 User 5
8 | User 2 Organisation 2 18 User 4 User 1 User 5
9 | User 3 Organisation 2 12 User 4 User 1 User 5
10| User 4 Organisation 2 310 User 4 User 1 User 5
11| User 5 Organisation 2 161 User 4 User 1 User 5
You can change your formula starting in D2 to:
=INDEX($A$2:$A$11,MATCH(1,INDEX(($C$2:$C$11=LARGE(($B$2:$B$11=$B2)*$C$2:$C$11,COLUMNS($C2:C2)))*(COUNTIF($C2:C2,$A$2:$A$11)=0),),0))
What I changed:
Added ($B$2:$B$11=$B2) inside the LARGE which multiplies all the Usage values for other organizations by 0. Which then won't be picked up by the LARGE function.
Changed the ROWS(H$1:H1) to COLUMNS($C2:C2) so you can rank horizontally
I also changed the cell references to the entire dataset rows 2 to 11
Solution with possible empty Usage:
If the Usage is empty (for all users in the same organization) and you desire the First, Second, and Third column to be blank then also, like so:
A B C D E F
---------------------------------------------------------
1 | Name Organisation Usage First Second Third
2 | User 1 Organisation 1 8 User 3 User 5 User 2
3 | User 2 Organisation 1 10 User 3 User 5 User 2
4 | User 3 Organisation 1 222 User 3 User 5 User 2
5 | User 4 Organisation 1 1 User 3 User 5 User 2
6 | User 5 Organisation 1 14 User 3 User 5 User 2
7 | User 1 Organisation 2
8 | User 2 Organisation 2
9 | User 3 Organisation 2
10| User 4 Organisation 2
11| User 5 Organisation 2
We can accomplish this by checking if the entire Usage for the Organization is 0. Then we can blank out all the ranks for that Organization.
To check if the sum of the usages for the organization is 0 we can use SUMPRODUCT: So for cell D2 that would look like:
=SUMPRODUCT(($C$2:$C$11)*($B$2:$B$11=$B2))=0
Then we can just wrap an IF around everything and blank it if the above statement returns true. So our final formula would look like:
=IF(SUMPRODUCT(($C$2:$C$11)*($B$2:$B$11=$B2))=0,"",INDEX($A$2:$A$11,MATCH(1,INDEX(($C$2:$C$11=LARGE(($B$2:$B$11=$B2)*$C$2:$C$11,COLUMNS($C2:C2)))*(COUNTIF($C2:C2,$A$2:$A$11)=0),),0)))
^^ Throw whatever you want in there
Now if you want the text to say anything else, just put that text inside the quotes for the TRUE condition of the IF statement.
Related
I'm using the GridDB Node js Connector and was wondering how I could add multiple tables in a single container while retaining data for all of the tables?
P.S. I went through the SQL documentation for GridDB, so using the JOIN command is not confusing; it is simply the cluster intiliazation. The code from the documentation is attached below:
○Inner join
SELECT * FROM employees e INNER JOIN departments d ON e.department_id=d.department_id;
id first_name department_id department_id department
------+-----------+--------------+--------------+-----------
0 John 0 0 Sales
1 William 1 1 Development
2 Richard 0 0 Sales
4 Lisa 3 3 Marketing
5 James 1 1 Development
○Left outer join
SELECT * FROM employees e LEFT JOIN departments d ON e.department_id=d.department_id;
id first_name department_id department_id department
------+-----------+--------------+--------------+-----------
0 John 0 0 Sales
1 William 1 1 Development
2 Richard 0 0 Sales
3 Mary 4 (NULL) (NULL)
4 Lisa 3 3 Marketing
5 James 1 1 Development
I have a data file (stat_data_raw.dat). I need to build such a diagram based on it.
Is it possible to do it this way in gnuplot? I broke my head while trying to do this in gnuplot. Such a chart as in the picture is built in Excel.
Data file: stat_data_raw.dat ( https://dropmefiles.com/oeO1L )
Build in Excel: pivot_and_chart.xlsx ( https://dropmefiles.com/xdoqy )
I've already tried a lot. I am using gnuplot v5.4 patchlevel 3.
I have already visited a bunch of pages on the Internet, including the official website and Stack Overflow. But I could not find a suitable script for me to adapt for myself. Even though I know some algorithmic programming languages, the syntax of gnuplot seems strange and confusing to me. It is a pity that there is no visual editor in which one could build and set up a graph, and then export it to the gnuplot format.
I also visited the page http://gnuplot.sourceforge.net/demo_5.4/boxes3d.html many times, but the example given there is too simple. The data in the candlesticks.dat file is very primitive.
I tried to build a graph based on the stat_data_matrix.dat file
(https://dropmefiles.com/omptl)
The data is in the form of a matrix. I can prepare the input data in any format (in the form of a matrix or, as in the first case, flat data). I don't know how best to work with gnuplot.
The maximum that I got on the matrix data:
set terminal qt size 1920, 1080
set encoding utf8
set datafile separator '\t'
set xyplane 0
set boxwidth .3
set boxdepth .3
set cbrange [0.5:15]
unset key; unset colorbox
set view 44, 200
splot for [col = 2:30] 'c:\LOAD\GNUPLOT\stat_data_matrix.dat' u ($0):(col):(column(col)):(col):xtic(1) with boxes lc pal title columnhead
The examples on the gnuplot homepage are a starting point, but sometimes it requires a lot more (commands, experience and understanding) to get the desired graph with all "tricks" and "treats".
I took your text data (not the matrix data).
Your datafile separator is actually TAB, although it might be easier to keep separator whitespace (and not switch to TAB only, i.e. datafile separator tab).
Hence, the first column is a time format, the second column is just "user", the 3rd column the user number, and the 4th column the z-value. I guess it is redundant to write 32 times "user" on the tic label, so I put it once into the y-label.
Some more comments:
time in gnuplot is handled as seconds from 01.01.1970 00:00:00, that's why the boxwidth is 24*3600 = 1 day, and tic spacing says set xtics 24*3600.
this type of graphical representation is not optimal since (depending on the viewing angle) you might hide some data, e.g. data from user 11 is partly hidden by data from user 12. So, you could also play with the viewing angle to improve or maybe sort the users to avoid this.
the 3D-bars are now centered on the grid lines. If you want to have the grid lines at the edges of the bars (like in your Excel image) you have play some more "tricks".
Look at the example below which should be starting point for further tweaking.
Check help datafile separator, help timecolumn, help view, basically to every command you should find a help entry.
Update:
Now with added labels of the z-value . Check plotting style with labels (check help labels).
grid lines are now at the border or the 3D-bars (earlier: centered) check help mxtics.
what I haven't found out yet is how to rotate the tic labels in a 3D plot. I asked a question about this and maybe there will be a better answer than mine which is placing and rotating the tic labels "manually".
As mentioned earlier, depending on the data, hiding of data by higher 3D-bars in front probably cannot be avoided completely. In order to minimize this the users are sorted by highest average. For this, you need to implement a few more lines:
you plot the data to tables (check help table) using the options smooth unique and smooth zsort (check help smooth).
then you are (mis-)using stats (check help stats) to put the order of users into the variable USERS.
during plotting you are using the ternary operator (check help ternary) to filter the data and plot it in the sequence given by USERS.
to get the ytic labels right, you have to place the labels via ytic(...), check help xticlabels.
Edit: if you set the tics via yticlabels(), you won't see the mytics anymore and the minor y-grid lines will not show up. Hence, you have to add the ytic labels manually (pretty annyoing)!
As you can see, if you want to rearrange data a bit it can get pretty awkward in gnuplot, which is not easy to understand for a beginner. Well, gnuplot wants to be a plotting tool, not a data processing tool.
Data: SO73521453.dat (TAB cannot be displayed here, but in the example below we are using whitespace anyway)
Date User Count
2022-07-29 User 1 53
2022-07-29 User 2 3
2022-07-29 User 3 1
2022-07-29 User 4 2
2022-07-29 User 5 1
2022-07-29 User 6 5
2022-07-29 User 7 1
2022-07-29 User 8 1
2022-07-30 User 1 2
2022-07-30 User 2 2
2022-07-30 User 6 1
2022-07-30 User 9 1
2022-07-31 User 1 1
2022-07-31 User 10 1
2022-08-01 User 1 37
2022-08-01 User 2 1
2022-08-01 User 11 1
2022-08-01 User 3 2
2022-08-01 User 4 4
2022-08-01 User 5 1
2022-08-01 User 6 7
2022-08-01 User 9 1
2022-08-01 User 8 1
2022-08-01 User 12 12
2022-08-02 User 1 40
2022-08-02 User 3 2
2022-08-02 User 4 13
2022-08-02 User 5 1
2022-08-02 User 6 6
2022-08-02 User 10 1
2022-08-02 User 12 11
2022-08-03 User 1 25
2022-08-03 User 2 5
2022-08-03 User 13 4
2022-08-03 User 3 4
2022-08-03 User 14 2
2022-08-03 User 4 10
2022-08-03 User 5 1
2022-08-03 User 6 5
2022-08-03 User 15 1
2022-08-03 User 12 2
2022-08-04 User 1 81
2022-08-04 User 3 1
2022-08-04 User 14 1
2022-08-04 User 4 2
2022-08-04 User 5 1
2022-08-04 User 6 1
2022-08-04 User 16 2
2022-08-04 User 17 2
2022-08-04 User 10 1
2022-08-04 User 18 1
2022-08-04 User 12 6
2022-08-05 User 1 40
2022-08-05 User 14 2
2022-08-05 User 4 3
2022-08-05 User 6 3
2022-08-05 User 9 3
2022-08-05 User 10 1
2022-08-05 User 19 1
2022-08-05 User 15 1
2022-08-05 User 18 4
2022-08-05 User 12 17
2022-08-06 User 1 1
2022-08-07 User 1 1
2022-08-07 User 12 2
2022-08-08 User 1 30
2022-08-08 User 13 8
2022-08-08 User 3 3
2022-08-08 User 4 12
2022-08-08 User 5 3
2022-08-08 User 6 3
2022-08-08 User 20 2
2022-08-08 User 12 19
2022-08-08 User 21 1
2022-08-09 User 1 51
2022-08-09 User 11 2
2022-08-09 User 13 6
2022-08-09 User 4 4
2022-08-09 User 6 5
2022-08-09 User 22 1
2022-08-09 User 12 12
2022-08-09 User 21 1
2022-08-09 User 23 1
2022-08-10 User 1 61
2022-08-10 User 2 2
2022-08-10 User 13 2
2022-08-10 User 4 2
2022-08-10 User 6 1
2022-08-10 User 24 1
2022-08-10 User 25 1
2022-08-10 User 15 1
2022-08-10 User 12 10
2022-08-10 User 21 1
2022-08-11 User 1 27
2022-08-11 User 2 4
2022-08-11 User 13 2
2022-08-11 User 14 2
2022-08-11 User 4 2
2022-08-11 User 5 1
2022-08-11 User 6 7
2022-08-11 User 26 1
2022-08-11 User 12 16
2022-08-12 User 1 23
2022-08-12 User 11 1
2022-08-12 User 13 7
2022-08-12 User 3 1
2022-08-12 User 4 1
2022-08-12 User 6 11
2022-08-12 User 20 1
2022-08-12 User 10 1
2022-08-12 User 12 4
2022-08-13 User 11 2
2022-08-14 User 1 2
2022-08-15 User 1 59
2022-08-15 User 2 3
2022-08-15 User 13 5
2022-08-15 User 3 2
2022-08-15 User 14 1
2022-08-15 User 4 3
2022-08-15 User 5 1
2022-08-15 User 6 9
2022-08-15 User 24 1
2022-08-15 User 26 1
2022-08-15 User 27 1
2022-08-15 User 28 1
2022-08-15 User 12 6
2022-08-15 User 23 2
2022-08-16 User 1 53
2022-08-16 User 11 1
2022-08-16 User 13 2
2022-08-16 User 3 1
2022-08-16 User 6 2
2022-08-16 User 24 1
2022-08-16 User 9 1
2022-08-16 User 12 7
2022-08-17 User 1 58
2022-08-17 User 11 2
2022-08-17 User 13 2
2022-08-17 User 3 2
2022-08-17 User 4 3
2022-08-17 User 5 1
2022-08-17 User 6 9
2022-08-17 User 10 1
2022-08-17 User 29 1
2022-08-17 User 12 23
2022-08-17 User 21 1
2022-08-18 User 1 54
2022-08-18 User 2 3
2022-08-18 User 11 1
2022-08-18 User 13 5
2022-08-18 User 3 1
2022-08-18 User 5 1
2022-08-18 User 6 2
2022-08-18 User 28 1
2022-08-18 User 8 1
2022-08-18 User 12 17
2022-08-19 User 1 64
2022-08-19 User 2 1
2022-08-19 User 13 2
2022-08-19 User 3 1
2022-08-19 User 6 5
2022-08-19 User 24 2
2022-08-19 User 9 1
2022-08-19 User 8 1
2022-08-19 User 12 2
2022-08-20 User 1 1
2022-08-20 User 11 2
2022-08-20 User 6 2
2022-08-21 User 1 2
2022-08-21 User 6 3
2022-08-22 User 1 60
2022-08-22 User 2 2
2022-08-22 User 11 1
2022-08-22 User 13 7
2022-08-22 User 3 1
2022-08-22 User 5 1
2022-08-22 User 6 10
2022-08-22 User 28 1
2022-08-22 User 8 1
2022-08-22 User 12 16
2022-08-22 User 23 1
2022-08-23 User 1 31
2022-08-23 User 2 1
2022-08-23 User 13 4
2022-08-23 User 14 1
2022-08-23 User 6 3
2022-08-23 User 16 1
2022-08-23 User 18 1
2022-08-23 User 12 15
2022-08-24 User 1 50
2022-08-24 User 13 2
2022-08-24 User 3 3
2022-08-24 User 14 1
2022-08-24 User 5 2
2022-08-24 User 6 5
2022-08-24 User 9 1
2022-08-24 User 28 1
2022-08-24 User 12 3
2022-08-25 User 1 32
2022-08-25 User 11 1
2022-08-25 User 13 4
2022-08-25 User 30 1
2022-08-25 User 5 2
2022-08-25 User 6 4
2022-08-25 User 16 1
2022-08-25 User 9 1
2022-08-25 User 15 1
2022-08-25 User 12 24
2022-08-26 User 1 11
2022-08-26 User 2 1
2022-08-26 User 13 8
2022-08-26 User 5 1
2022-08-26 User 6 7
2022-08-26 User 31 14
2022-08-26 User 28 1
2022-08-26 User 12 2
2022-08-27 User 2 2
2022-08-27 User 5 1
2022-08-27 User 31 2
2022-08-27 User 9 2
2022-08-27 User 28 1
2022-08-28 User 28 1
Script:
### 3D bars with labels and sorting
reset session
FILE = "SO73521453.dat"
# sort users by highest average
set table $Temp1
plot FILE u 3:4 smooth unique # get average for each user
set table $Temp2
plot $Temp1 u 1:2:(-$2) smooth zsort # sort by highest average
unset table
USERS = ''
stats $Temp2 u (USERS=sprintf("%s %d",USERS,$1)) nooutput # get user order in a string
set datafile separator whitespace
set format x "%b %d" timedate
myBoxSize = 1.0
set boxwidth 24*3600*myBoxSize
set boxdepth myBoxSize
set wall y0 fc "white"
set wall x1 fc "white"
set xyplane at 0
set xtics 24*3600 out scale 0,1 font ",7" offset -1,0.2
set mxtics 2
set ytics 1 out scale 0,1 font ",7" offset 0,0.2
set mytics 2
set ylabel "user" rotate parallel font ",14" offset 0,1
set grid mx,my,z lt 1 lc "grey"
set key noautotitle
set xrange [:] noextend reverse
set yrange [0.5:words(USERS)+0.5] noextend
set view 30,225
set style textbox opaque fc rgb 0x77ffffff
set format y ""
set for [i=1:words(USERS)] label i word(USERS,i) at graph 0, first i, first 0 \
offset 0,-0.5,0 rotate by 0 left font ",9"
splot for [i=1:words(USERS)] FILE u (timecolumn(1,"%Y-%m-%d")):(i):\
($3==word(USERS,i)?$4:NaN):(i) w boxes lc var, \
for [i=1:words(USERS)] '' u (timecolumn(1,"%Y-%m-%d")):(i):\
($3==word(USERS,i)?$4:NaN):4 w labels boxed font ",8"
### end of script
Result: (certainly still to be optimized)
I have a data set (a lot more columns involved than example) however, want to summarize outcomes on a separate sheet.
Well, can’t use pivots as I have to drop data in from an external source prior to the desired outcome.
Staff names will not be sorted also. There are 9 possible outcomes of 1 visit.
DATA EXAMPLE
Staff Name Status Of Visit
Staff 1 Successful 1
Staff 1 Successful 2
Staff 1 Unsuccessful 1
Staff 1 Unsuccessful 2
Staff 1 Closed 1
Staff 1 Successful 3
Staff 1 Successful 4
Staff 1 Successful 5
Staff 1 Closed 2
Staff 2 Closed 1
Staff 2 Successful 2
Staff 2 Closed 1
Staff 2 Unsuccessful 1
Staff 3 Successful 3
Staff 3 Successful 1
Desired Output
Staff Name Successful Unsuccessful Closed
Staff 1 5 2 2
Staff 2 1 1 1
Staff 3 2 0 0
and this is the formulas i have used for the staff names
=UNIQUE(staffnames)
and for the counts
=COUNTIFS(staffnames,$D3,B:B,E$2&"*")
but i assume there may be much better way to resolve this, can anyone help
You can try:
Formula in D1:
=LET(X,TRANSPOSE(UNIQUE(TEXTBEFORE(B2:B16," ",-1))),Y,UNIQUE(A2:A16),VSTACK(HSTACK(A1,X),HSTACK(Y,COUNTIFS(A2:A16,Y,B2:B16,X&"*"))))
I have two sheets sheet 1 and sheet 2, what I have to do is copy the values in sheet 1 to sheet 2
sheet 1 : I have two type of users with corresponding weights
user 1 user 2 7
user 1 user 3 19
user 1 user 7 5
user 3 user 2 1
user 2 user 7 1
sheet 2
user 1 user 2 user 3 user 7
user 1
user 3
user 2
user 7
The final result should be something like this: user 1 - > user two has weight 7 so this value appears in that cell and so on
user 1 user 2 user 3 user 7
user 1 0 7 19 5
user 3 0 1 0 0
user 2 0 0 0 1
user 7 0 0 0 0
Is there a way to do this? I know I can pass values between two excel sheets but I'm confused how to do this in this case
UPDATED: CIRCULAR REFERENCE ERROR
sheet 2
Assuming both the sample you have given starts from the top left of the sheet, enter the following formula in B2 (for user 1, user 1) and drag across the table:
=SUMIFS(Sheet1!$C:$C,Sheet1!$A:$A,$A2,Sheet1!$B:$B,B$1)
The output will be:
user 1 user 2 user 3 user 7
user 1 0 7 19 5
user 2 0 0 0 1
user 3 0 1 0 0
user 7 0 0 0 0
It uses the users in the row and column as the criteria to match the same in column 1 and 2 of sheet 1, and adds the weight. This will work regardless of whether there is duplication or not.
In my worksheet I have the following data that tells me how many people are in a certain job role using a =countif() statement from another worksheet:
Job Role|Amount of people in the role
Job 1 | 6
Job 2 | 26
Job 3 | 4
Now I have done is in my worksheet I have used Job 1, Job 2 and Job 3 as headings to 3 separate tables below this table like this:
Job Role|Amount of people in the role
Job 1 | 6
Job 2 | 26
Job 3 | 4
Job 1 Job 2 Job3
Name|Job Role Name|Job Role Name|Job Role
All I would like to do at the moment is to populate each of the 3 tables with the job role based on the amount that is in the top table, for example, under the Job 1 table, I would like the job role to repeat 6 times (I cannot just type this in because I want this to work automatically just in case another employee gets added to the employee list I have).
Job 1
Name|Job Role
1 |Job 1
2 |Job 1
3 |Job 1
4 |Job 1
5 |Job 1
6 |Job 1
and the same for job 2 (which will have 26 repeated rows) and job 3 which will have 4 rows. Any help would be greatly appreciated.
Just in case anybody is curious I have solved this. First of all I figured out that I could add a ROW ID for each row of data in each job 1, job 2 and job 3 tables and make it so that it would not go over the amount of people stated in the top table like this:
A B C
1 Job Role|Amount of people in the role |
2 Job 1 | 6 |
3 Job 2 | 26 |
4 Job 3 | 4 |
5
6 Job 1
7 ID |Name |Job Role
8 1 |t |
9 2 |b |
10 3 |a |
11 4 |s |
12 5 |d |
13 6 |f |
To get the number to go to 6 and not go over this, i used this formula (IN CELL A8) to automatically give the row an ID if an employee is taken away or added:
=IF(ROW()-7>B2,"",ROW()-7)
This statement basically says "if the row number -7 is HIGHER than B2 (6 in the table), then leave a blank space, if the row number is LOWER then B2 then return the row number -7 = 1 and when pulled down this will carry on until 6 and then start to leave blank spaces unless another employee of the Job 1 job role is added which in case case it will go up to 7.
To return the job role this was pretty easy when I have the ID numbers, the statement I used in cell C8 was:
=IF(A8<>"",A6,"")
This basically means that if the ID column has something in it then return the Job Role so I end up with what I want:
Job 1
ID | Name |Job Role
1 | T |Job 1
2 | B |Job 1
3 | A |Job 1
4 | S |Job 1
5 | D |Job 1
6 | F |Job 1
you must use power query
You can simply add a column with this formula:
=Text.Repeat("a",[column with repeated times])
In column 5 should be the count you want for rows to be duplicated.
Then, from transform tab, split the new column by number of characters, use 1 char split, but from advanced settings, make sure you split into rows, not into columns, this will duplicate all other columns.