Custom sort ssrs matrix - reporting-services

I have a matrix report that has four columns and is sorted descending on the last columns values. The problem I have is when there is a tie I would like to use the value in the prior column or the one prior to that if there is still a tie. Below is a sample of my output and what I'm after is for Nissan and Renault to be switched. This is the expression I'm currently using in my group sort
=IIF(Fields!YearSold.Value = MAX(Fields!YearSold.Value),0, Fields!UnitSold.Value)
2009 2010 2011 2012
Make Units Units Units Units
Chevy 1,104 842 811 927
Volvo 1,054 905 792 879
Ford 1,638 923 718 809
Nissan 918 794 725 791
Renault 840 698 759 791
Mazda 722 535 460 621
Lexus 786 590 551 563

You can sort a tablix on multiple columns. Edit the tablix Sort properties, adding the additional columns in order - the tablix will be sorted that order, starting with the top column.

Related

Finding Total Percentage From 3 Different Mysql Table

table_1
ST_ID NAME MATHS GEOGRAPHY ENGLISH
1001 Alan Wegman 80 85 70
1002 Robert Franko 79 65 60
1003 Francis John 90 75 67
1004 Finn Harry 88 87 93
table_2
ST_ID NAME MATHS GEOGRAPHY ENGLISH
2001 Alan Wegman 69 75 80
2002 Robert Franko 99 85 70
2003 Francis John 80 65 77
2004 Finn Harry 78 97 83
table_3
ST_ID NAME MATHS GEOGRAPHY ENGLISH
3001 Alan Wegman 90 81 72
3002 Robert Franko 97 65 61
3003 Francis John 74 75 67
3004 Finn Harry 77 88 73
From above three tables, i want to to the following, i want to take value of MATHS of student Alan Wegman which is 80 divide by 100 from TABLE 1 then take value of GEOGRAPHY of the same student Alan Wegman which is 85 divide by 100 from TABLE 3 then from last table take value of ENGLISH of same student Alan Wegman which is 70 divide by 100 then they should be added to get one value like this example (80/100+85/100+70/100) and output should be displaying NAME and total value after addition example below
Alan Wegman 2.27
Robert Franko 2.11
Finn Harry 3.29
Is this really possible? i want this to be performed by a single query for all records or if there is an alternative way of doing this please share with me, the query i am trying to achieve this result is this one below but it does not return any thing i don't know where am wrong.
select
table_1.NAME MATHS/100+table_2.NAME GEOGRAPHY/100+table_3.NAME ENGLISH/100
WHERE table_1.NAME = table_2.NAME = table_3.NAME
I am not competent with mysql need help here guys.

Ranking Based On Aggregate Sum Derived Table Without #variables

This is been a headache challenge for me in my project, being a php and or say sql novice.
I must first of all indicate that i'm running this code in php with binded params, since I am using pdo.
Now, as the title indicates, how can I rank students in a class, after having calculated their raw scores from Aggregate Sum Derived Table (From Clause), without #variables in sql. Something like, let assume my data pulled from the database is:
studref Name English Maths Gov
Bd1 Ida 66 78 49
Bd2 Iyan 58 80 69
Bd3 Ivan 44 56 80
Bd4 Iven 63 92 68
Bd5 Ike 69 77 59
So using Aggregate Sum in derived table, I then add another column, which is summation of the marks from the various subjects like:
SUM(THE SCORES) AS accum_raw_scores
studref Name English Maths Gov accum_raw_scores
Bd1 Ida 66 78 49 193
Bd2 Iyan 58 80 69 207
Bd3 Ivan 44 56 80 180
Bd4 Iven 63 92 68 223
Bd5 Ike 69 77 59 205
So, what I want to do next is to add another column, which will represent the rank of each student, based on his/her total score from the subjects. Hence, this is where I want the code below to handle that for me:
1+(SELECT COUNT(*)
FROM (SELECT s.studref, SUM(s.subjectscore) AS total_score
FROM studentsreports s
GROUP BY s.studref) AS sub
WHERE sub.total_score > main.accum_raw_scores) AS overall_position,
So that in the end, I will have something like:
studref Name English Maths Gov accum_raw_scores rank
Bd1 Ida 66 78 49 193 4
Bd2 Iyan 58 80 69 207 2
Bd3 Ivan 44 56 80 180 5
Bd4 Iven 63 92 68 223 1
Bd5 Ike 69 77 59 205 3
Unfortunately, I have tried several approaches but to no success. Please help!
Meanwhile, I want to try as much as possible to do without variables.

Webscraping the data using R

Aim: I am trying to scrape the historical daily stock price for all companies from the webpage http://www.nepalstock.com/datanepse/previous.php. The following code works; however, it always generates the daily stock price for the most recent (Feb 5, 2015) date only. In another words, output is the same, irrespective of the date that I entered. I would appreciate if you could help in this regard.
library(RHTMLForms)
library(RCurl)
library(XML)
url <- "http://www.nepalstock.com/datanepse/previous.php"
forms <- getHTMLFormDescription(url)
# we are interested in the second list with date forms
# forms[[2]]
# HTML Form: http://www.nepalstock.com/datanepse/
# Date: [ ]
get_stock<-createFunction(forms[[2]])
#create sequence of dates from start to end and store it as a list
date_daily<-as.list(seq(as.Date("2011-08-24"), as.Date("2011-08-30"), "days"))
# determine the number of elements in the list
num<-length(date_daily)
daily_1<-lapply(date_daily,function(x){
show(x) #displays the particular date
readHTMLTable(htmlParse(get_stock(Date = x)), which = 7)
})
#18 tables out of which 7 is one what we desired
# change the colnames
col_name<-c("SN","Traded_Companies","No_of_Transactions","Max_Price","Min_Price","Closing_Price","Total_Share","Amount","Previous_Closing","Difference_Rs.")
daily_2<-lapply(daily_1,setNames,nm=col_name)
Output:
> head(daily_2[[1]],5)
SN Traded_Companies No_of_Transactions Max_Price Min_Price Closing_Price Total_Share Amount
1 1 Agricultural Development Bank Ltd 24 489 471 473 2,868 1,359,038
2 2 Arun Valley Hydropower Development Company Limited 40 365 360 362 8,844 3,199,605
3 3 Alpine Development Bank Limited 11 297 295 295 150 44,350
4 4 Asian Life Insurance Co. Limited 10 1,230 1,215 1,225 898 1,098,452
5 5 Apex Development Bank Ltd. 23 131 125 131 6,033 769,893
Previous_Closing Difference_Rs.
1 480 -7
2 363 -1
3 303 -8
4 1,242 -17
5 132 -1
> tail(daily_2[[1]],5)
SN Traded_Companies No_of_Transactions Max_Price Min_Price Closing_Price Total_Share Amount Previous_Closing
140 140 United Finance Ltd 4 255 242 242 464 115,128 255
141 141 United Insurance Co.(Nepal)Ltd. 3 905 905 905 234 211,770 915
142 142 Vibor Bikas Bank Limited 7 158 152 156 710 109,510 161
143 143 Western Development Bank Limited 35 320 311 313 7,631 2,402,497 318
144 144 Yeti Development Bank Limited 22 139 132 139 14,355 1,921,511 134
Difference_Rs.
140 -13
141 -10
142 -5
143 -5
144 5
Here's one quick approach. Note that the site uses a POST request to send the date to the server.
library(rvest)
library(httr)
page <- "http://www.nepalstock.com/datanepse/previous.php" %>%
POST(body = list(Date = "2015-02-01")) %>%
html()
page %>%
html_node(".dataTable") %>%
html_table(header = TRUE)

Matlab using accumarray with cell array

I am quite new to Matlab, but I have some experience with other programming languages. I have a very large table imported from MySQL in Matlab. It is given as cell array that looks something like this:
date key sales weight name
12/11 101 1200 20 blue
12/11 178 1200 70 purple
13/11 209 1300 15 purple
12/11 101 1200 10 blue
14/11 678 1200 10 yellow
12/11 340 1500 30 green
17/11 178 1900 50 purple
And I want the output to be this:
key sales weight name
101 2400 30 blue
178 3100 120 purple
209 1300 15 purple
678 1200 10 yellow
340 1500 30 green
So I would like to combine the rows which have the same number in the column 'key'. Meanwhile I would like to sum the column 'sales' and 'weight' and keep the column 'name' (each 'key' has the same 'name', but each 'name' can have multiple 'keys')
I know this is possible with a for loop, but as I am having to manipulate a lot of tables in similar but different ways this is computational intensive.
I have read in similar problems this can be solved using accumarray, but can this be done with accumarray with a sub as cell array? And how would that look like?
Here is one method using accumarray, however it might be worth your while to consider the new table data structure instead of a cell matrix (I'm sure you can easily convert to it)
T = { 101 1200 20 'blue'
178 1200 70 'purple'
209 1300 15 'purple'
101 1200 10 'blue'
678 1200 10 'yellow'
340 1500 30 'green'
178 1900 50 'purple'};
[u, ind, x] = unique([T{:,1}])
key = T(ind,1)
sales = accumarray(x', [T{:,2}])
weight = accumarray(x', [T{:,3}])
name = T(ind,4)
[key, num2cell(sales), num2cell(weight), name]
x={ '12/11' 101 1200 20 'blue'
'12/11' 178 1200 70 'purple'
'13/11' 209 1300 15 'purple'
'12/11' 101 1200 10 'blue'
'14/11' 678 1200 10 'yellow'
'12/11' 340 1500 30 'green'
'17/11' 178 1900 50 'purple'};
[~,b,c]=unique([x{:,2}]);
y=[x(b,2),...
num2cell(sparse(1,c,[x{:,3}]))',...
num2cell(sparse(1,c,[x{:,4}]))',...
x(b,[5])];
unique is used to get the indices of duplicate keys. sparse is used to get the sum.

getting a full line from unique first two columns

I have two files, and need to find the line given from a unique set of the first two columns.
Essentially, I have
File 1:
11 23 0.98 0.43
13 15 0.87 0.23
14 18 0.96 0.43
23 42 0.55 0.64
and
File 2:
11 14 0.64 0.47
11 23 0.77 0.34
13 15 0.87 0.23
42 23 0.65 0.55
and need an output of
11 14 0.64 0.47
Most things I've seen require some form of reordering of the first two columns, which needs to be avoided. Thank you in advance!
You can use a loop for this, here is some pseudo-code:
for every item x in the first column
for every item y in the second column
if x is equal to y then
//do your stuff here