Top 2 positions in every company (based on their CTC) - pandas

My data set contains company column, job position and ctc column. I want to get top 2 positions in each company based on CTC. Did some group by as below...
I tried -
grp112 = df23.groupby(['company_name','job_position'],as_index=False)['ctc'].max()
df24= pd.merge(df23, grp112, on=['company_hash','job_position'], how='inner',suffixes=(None,'_maxCtc'))
Above 2 lines will show job position based on max ctc, I am not sure how to get 2nd highest paid job position !

Related

Ranking error when total score is 100 percent

I've created a ranking system for result that contains score from 1 to 100, when a student gets 100 percent the system ranks the student last in class. I expected the system to rank the student with 100 percent as 1st in class.
I got the result below where the student came out 11th position out of 11 student in the class. My expectation is that this particular student supposed to be the 1st position in class instead of the last position.
Please, i need the help of someone
Thanks
enter image description here

How can i loop through all records from jan till dec and assign a value based on hierarchy

I have a data set of members and their health condition, and every health condition has a value associated with them and also every health condition falls in a group. in the group there is a hierarchy for example group A have (8,9,10,11,12).in this group the highest in hierarchy is 8. All these numbers have values assigned to them for example 8=0.71 9=0.61 and so on. and if 8 is captured first, then it should take the value assigned to 8 which is 0.71 if 8 (or any other condition) is captured later then it should only take the difference of both of them. for example, if 9 is captured first and then 8 is captured then it will be 0.71-0.61=0.10 value.
[enter image description here][1]
[1]: https://i.stack.imgur.com/kg5YD.png
in the picture, on scenario1, you can see that if a health condition '10' is captured on 1/15 then the column F will take the full value of the Health condition. next on 1/16 another health condition is captured and falls in same disease group then it takes the difference of the both values. (0.65-0.55=0.1)
in scenario 2, you can see that for same member same health condition,10, is captured in 02/18 so this time the column F will show only zero because this condition was already captured
please help.
thanks

Exclude one dimension from total count / sum in qlik

I want to have the %-Share of a value in Qlik. I have two dimension and on KPI which I am using in a distribution graph:
The data is:
Point Brand Business
A AA 1
B AA 1
C AA 1
Right now i am using the formula: Count([Business])/Count(total [Business]), on my Y-Achse I have the Brand and my point is Point, Right now he is calculating the Super total, but How can I only calculate the total for the Brand? Something like Count([Business])/Count(total [Business], if Brand == Brand)
You should add Brand field as aggregation scope
count([Business]) / Count(total <Brand> [Business])
From Qlik's documentation
By using TOTAL [], where the TOTAL qualifier is followed by a list of one or more field names as a subset of the chart dimension variables, you create a subset of the total possible values.
Adding the field to the total can be translated as: count all Business but aggregated by Brand. And since Brand is also a dimension to the chart then for each row Count Total will be the count for the current Brand value

ssrs report : Facing issues with Master detail kind of report

I need to generate a report of below format. The header repeats only per page.
ItemNr | ItemGenDesc | FulfilmentBin | onHand
-----------------------------------------------
CAP100 Capacitor FulFil1 5
binPriority | binBackup | binBackupQty | binMin | binMax
-----------------------------------------------------------------
1 bkBUSLOT2 100 1 5
2 bkBUSLOT3 150 2 6
CAP400 Transistor FulFil12 20
CAP500 Transistor FulFil14 30
binPriority | binBackup | binBackupQty | binMin | binMax
-----------------------------------------------------------------
1 bkBUSLOT5 250 5 9
My SQL output is as below
I tried to work with 2 tablix and somehow I got the output coming up in preview mode but when I export to PDF, I get blank lines between each item. I am guessing that's because the binPriority grid (detail grid) is hidden when the itemnr count <=1. Also the tablix1 row header appears for every grouping but I want row header to appear once per page.
Can anyone suggest what are the ways to generate this type of report?
Thanks.
Update 1 : Sorry CAP500 in the report should be Radiator. My typo mistake. The report should be grouped by ItemNumber and it is sorted by binPriority. So it will print binpriority=0 in the master grid and then in the detail grid it will print in the order of binPriority. The OnHand that is shown in the master grid is relevant to binPriority= 0.
You can achieve your specified layout with a single Tablix. This is fairly simple if you don't mind Columns 2-4 in your Group heading lining up with Columns 1-3 in your Detail. Since horizontal page real estate isn't really an issue (only 6 columns counting the blank column to the left of your Detail columns), I would take this route.
I'm not sure how much you know about SSRS, so forgive me if this explanation is too rudimentary. Others with less experience than you might find it helpful as well.
Right Click the Detail Row on your Tablix.
Select Add Group => Row Group => Parent Group.
Set the Group By value to ItemNumber and check the "Add Group Header" box.
This creates a Group By Column, which I would delete for your specified layout. Make sure to only delete the Column, not the Row Group.
In the Grouping Window (down at the bottom by default), right click the ItemNumber Row Group and select Group Properties.
On the Sorting tab/menu, set the Sort By value to binPriority.
Right Click your new Row Group Row on the Tablix and select Insert Row => Inside Group Above. You'll need to do this twice so you have 3 Row headings in the Row Group.
Insert 3 more columns for a total of 6 columns in your Tablix.
Put your ItemNr, ItemGenDesc, FulfilmentBin, onHand Labels and Values in the first two Rows, first 4 Columns of your Row Group.
Put your binPriority, binBackup, binBackupQty, binMin, binMax Labels in the Last Row, Last 5 columns of your Row Group.
Put your binPriority, binBackup, binBackupQty, binMin, binMax Values in the Last 5 columns of your Detail Row.

SSRS - Is there a way to have a table split by a page break to appear on the same page?

I am creating a report using MS Report Builder 3.0. For this report, I have a stored procedure built that filters down to the specific rows needed, and then I use a row group to group on a particular field (pass_no). The table that is displayed is 2 columns and 3 rows within the row group. The basic description of what I want to accomplish is instead of the rows running onto the next page, I want the rows to continue on the same page in a new set of 2 columns. Think of it like a newspaper where the text continues in a new column rather than running down onto the next page.
For the example I'm going to use here, there are 12 rows of data returned by the SP, and 8 unique values in the pass_no column which is what my row group is grouped on. So in the report I end up with 8 groups of 3 rows. I'm aiming to have the table display 6 pass_no values (so 6 groups of 3 rows) before, for lack of better terminology, starting a new table.
My first approach at this has been to create a column group and set the grouping expression to the following:
=Floor((RowNumber(Nothing) - 1) / 6)
While this works in creating a new set of 2 columns, the split for the new columns is based on the row number from the raw data returned by the SP rather than the number of rows sets created by the row group. So because there are 12 rows returned, and the 6th and 7th rows have the same pass_no value, the second set of columns duplicates that 1 set of data. Also, the top 6 rows of the second column set are blank with the second set of values appearing below the first set.
If I add an additional column group where it is also grouping by pass_no, then I don't get the duplicate values, but I do get a pair of columns for each pass_no as well (as would be expected). I've tried modifying the expression above a bit and changed Nothing to the row group name and have tried the table name, but neither of them have yielded the desired result.
I can't alter the SP to do the grouping there because there are other column values that are not identical and I pull that data into a cell value expression within the table using Join(LookupSet()).
I have also considered creating 2 tables and applying a filter to the table so the first table only displays the first 6 results and the second table displays the remaining results, but that also looks at the raw data rather than the groupings and TOP N can't be used on pass_no as it's a text value, not an integer. This would also cause problems if I need to go to 3 tables.
So long story short, is there a way to do a table break rather than a page break or to overflow columns onto the same page rather than onto a new page?
Here's the pertinent portions of the Dataset:
http://sqlfiddle.com/#!2/5082b/1
PASS_NO MASTERTRAN TRANS_NO DESCRIPTION IS_MOD
7913019000 4931019000 4931019000 General Admission Adult 0
7914019000 4932019000 4932019000 Sea Turtle Hosp Adult 0
7914019000 4932019000 4933019000 2:00 PM SEA TURTLE HOSP 1
7916019000 4934019000 4934019000 Sea Turtle Hosp Child 0
7916019000 4934019000 4935019000 2:00 PM SEA TURTLE HOSP 1
7917019000 4934019000 4934019000 Sea Turtle Hosp Child 0
7917019000 4934019000 4935019000 2:00 PM SEA TURTLE HOSP 1
7918019000 4934019000 4934019000 Sea Turtle Hosp Child 0
7918019000 4934019000 4935019000 2:00 PM SEA TURTLE HOSP 1
7922019000 4936019000 4936019000 General Admission Child 0
7923019000 4936019000 4936019000 General Admission Child 0
7924019000 4936019000 4936019000 General Admission Child 0
I think your data presents a bit of a problem.
As you've already figured out, typically for this sort of setup you'd set up a row group with an expression like:
=(RowNumber(Nothing) - 1) Mod 6
And a column group expression like:
=Ceiling(RowNumber(Nothing) / 6)
This would create a six row tablix that would grow horizontally as required.
See this SO question for a similar example.
However, you currently have the requirement of also grouping by another column - pass_no in your case. Normally you can approximate a group-level row number with an expression like:
=RunningValue(Fields!pass_no.Value, CountDistinct, "DataSet1")
Unfortunately, when you try to add this into one of the grouping expressions like:
=Ceiling(RunningValue(Fields!pass_no.Value, CountDistinct, "DataSet1") / 6)
You get the following error:
A group expression for the tablix 'Tablix1' includes the aggregate
function RunningValue. RunningValue cannot be used in group
expressions.
Based on all this, my recommendation is to try and get a Dataset that has one row per pass_no value and base the tablix on this, with the above row/column grouping expressions, i.e. no need to group on multiple pass_no rows. So in your example it would have eight rows. You could then have a separate Dataset with all the individual rows and use a lookupset function to concatenate the description, etc.
Your other option is to try and get everything on one Dataset only, including the aggregates as required. This might not be possible, but for description at least you can leverage any of the various techniques here to get a delimited list. Once you have this list you can replace the delimiter with vbCrLf to split it back over multiple rows.
All this is a very long-winded way of saying that I don't know if your requirement is possible with your data, but if you look at having at least one Dataset with one row per pass_no you should be able to make it work.