C# Objectlistview group only specific rows - objectlistview

I'm trying to group only specific items on my list, to be more exact I try to group them only if the property "x" on my model "y" is filled. Other item's should not be grouped at all if property "x" is empty. Rigth now I have this code below:
olv.ShowGroups = true;
OLVColumn column = new OLVColumn("HiddenGroupColumn", "propertyX");
column.IsVisible = false;
column.GroupKeyGetter = delegate (object x)
{
return ((modelY)x).propertyX;
};
olv.AlwaysGroupByColumn = column;
But it is sorting everything even the rows with empty propertyX value.
Is it somehow possible to group "only" rows that has propertyX filled and keep them inside list rather than adding them above or below the list?
For example:
No
Name
PropertyX(Not an actual column just property in model)
1
someStringHere
2
AnotherString
3
lorem
GRP1
4
ipsum
GRP1
5
asd
6
qwe
7
zxc
GRP2
8
ttt
GRP2
9
eee
I tried to explain as much as I can, in this instance is it possible to group row 3-4 together and group row 7-8 together while keeping them in their current position and NOT grouping the ones that has Empty string on propertyX?

Related

Trying to automate the numbering of Excel rows, but only semi sequentially, based on conditions

I'm trying to get a system set up on a data compilation sheet in excel. Going in and adding all the new information, and then deleting the old information has become extraordinarily tedious. I'll type out what I'm trying to accomplish, as an example.
A
B
C
Name
Date
Desired AutoNumber
Item 1
01/17/23
1
Item 1
01/17/23
1
Item 1
01/17/23
1
Item 1
01/06/23
2
Item 1
01/02/23
3
Item 1
01/02/23
3
Item 2
01/17/23
1
Item 2
12/24/22
2
Item 2
12/16/22
3
Item 2
11/18/22
4
Item 3
01/16/23
1
Item 3
01/16/23
1
Item 3
01/13/23
2
Item 3
01/11/22
3
Item 3
01/08/23
4
Item 3
12/26/22
5
Item 3
12/26/22
5
Wanting to use this format, as the most recent 5-7 dates per item are needed to remain. (This is for an online games' external assistant system)
What I've found either only numbers the rows based on item name, or based on the dates per item name, which isn't what I'm trying to make happen. What I've used so far is:
=countif($A$2:A2,A2) (which numbers based on item name) or
=countifs($A$2:A2,A2, $C$2:C2, C2) (which numbers based on the dates per item name, which is closer to what I'm looking for, but not in the right format)
By also adding in offset, it does the same thing.
=countif(offset($A$2:A2,0,0),A2)
I'm not sure if there's even a way to number it the way I'm looking to, since it's not numbering within a specified date parameter. I've been trying to do this without using a macro, since the information is going into a larger database, and certain information can't be deleted. Is there a way to do this using a formula?

Selectively updating the multilevel column name of a dataframe (python), a column with a specific text to have a particular name

I have a multi level column dataframe, where first two columns have text in level 1 (level 2 empty)and remaining column have date in level 2 (level 1 text).
S1 S2 _id _id
07-08-2016 00:00 14-08-2016 00:00
ABC ABC1 22071 19474
CDE CDE1 17 3
I tried something like this, but it is not working
pd.MultiIndex.from_tuples([(s1,s1) if isinstance(s1, datetime.date) else (s2) for s1,s2 in df.columns],names=.columns.names)
I tried an alternate way
df.columns = [(s2) if s1 == '_id' else (s1) for s1,s2 in df.columns]
I applied the if condition on string, but the ideal solution would be to identify dateformat in the multilevel column name

Sum values if multiple conditions met in different sheet

I have one sheet that creates a mapping of names to values (Map_Sheet). In another sheet there are values for each name in the mapping table (Data_Sheet). What I am trying to do is add values based on certain conditions in the mapping table. For example: I want to add all counts of dog by bread and color. So in the mapping table I would look for all dogs that are brown and of a certain bread and get their names and manually add them together. I want to have a formula that does the addition based upon multiple conditions from Map_Sheet.
Here is an example of the data:
Map_Sheet-
name|bread|color|age
a x b 2
b y w 3
c x b 2
d z f 4
Data_Sheet -
id|a|b|c|d
0 3 4 2 1
1 1 2 4 2
2 3 5 7 2
3 1 2 6 9
4 1 3 5 7
And for each ID in the data sheet I want a count of bread X with color B. So I would add for ID0 values for A and C, (3+2) - so ID0 = 5, etc for each id.
I cannot use VBA so I was looking into using INDEX and MATCH but I cannot wrap my head around it. Any ideas? Thanks!
If the row headers in the first sheet match the column headers in the second sheet, you can put this formula in (say) G2 of the second sheet.
=SUM(TRANSPOSE(Map!$C$2:$C$5="b")*C2:F2)
If the column headers in the second sheet were in a different order, you would have to use something like:-
=SUM(C2:F2*NOT(ISERROR(MATCH($C$1:$F$1,IF(Map!$C$2:$C$5="b",Map!$A$2:$A$5),0))))
Both of these are array formulae. You can add extra conditions to select breed as well as colour using the same basic pattern:-
=SUM(TRANSPOSE((Map!$C$2:$C$5="b")*(Map!$B$2:$B$5="x"))*C2:F2)
or
=SUM(C2:F2*NOT(ISERROR(MATCH($C$1:$F$1,IF((Map!$C$2:$C$5="b")*(Map!$B$2:$B$5="x"),Map!$A$2:$A$5),0))))

Excel: Return a single value based on two references

I have two values that a person would enter information for in column B:
Spreadsheet Name: Info
A B
1 Level 2
2 Class Class 2
In a second spreadsheet within the Workbook, i have a data spreadsheet with various tables.
So when a person enters information in !InfoB2 data validation drop down, it would return the name of the table the formula should use to search for the value in the Data table that's level is related to !InfoB2.
Spreadsheet Name: Data
Table Name: Class 1
A B
1 Level BAB
2 --------------------
3 1 8
4 2 3
Table Name: Class 2
A B
1 Level BAB
2 --------------------
3 1 2
4 2 7
So when someone enters Level: 2, and Class2, i would like it to return the value in the BAB column, how can i do this?
Edit
As ghetto as this is, it feels like it's on the right track, however it's returning #VALUE!
VLOOKUP(B1,VLOOKUP(B2,Class,2,FALSE),2,FALSE)
Table Class
Table Name: Class
A B
1 Class Name Table Name
2 Class 1 Class1Table
3 Class 2 Class2Table
You could try the following formula:
=INDEX(INDIRECT(B2&"[#All]"), MATCH(B1,INDIRECT(B2&"[[#All],[Level]]"),0), 2)
This takes the value of B2 (Class2 note I removed the space since table names can't contain spaces) and concatenates it with [#All] so you get: Class2[#All] (this is the table reference). INDIRECT converts the text into a valid range.
INDIRECT(B2&"[[#All],[Level]]") similarly gives the range Class2[[#All],[Level]].
MATCH(B1,Class2[[#All],[Level]],0) gives the row number in which the value in B1 is found (i.e. gives the row in which 2 is found, meaning the result is 4)
=INDEX(Class2[#All], 4, 2) then returns the value from range Class2[#All] in the 4th row and 2nd column.
If I understand correctly you will want to use INDIRECT and/or the structured reference syntax for this one.
I don't have access to Excel at the moment so I can't check to see if this would work. I'll update this answer once I try some stuff out.

Dictionary that has lists in keys, how to print so that the KEY with the least values in the list gets printed first?

So I have tried to do this extensively but to no avail.. I'm writting a program that takes a dictionary of names that have a list to them, and a numerical value of the amount of things in the list. I want to print each name in the list so that the first name that gets printed is the one with the least amount of values in the list, and the last name printed is the one with the most amount of values in the list.. here is my code. IT ONLY prints the name which is the key and then the whole list of values. and then it prints e which is the end. so
"anna"
3
4
5
6
e
"dan"
3
4
6
e
"cilla"
3
4
e
"billy"
6
e
...and so on
for GPS in GNR:
print('"'+GPS+'"')
for s in GNR[GPS]:
print(s)
print("e")
and here is the dictionary with its values.
GNR = {"anna":[3,4,5,6],"billy":[6],"cilla":[3,4],"dan":[3,4,6]}
So the result I would like is not the above but this:
"billy"
6
e
"cilla"
3
4
e
"dan"
3
4
6
e
"anna"
3
4
5
6
e
as you see it prints the name with the least values in its list first followed by the rest.
I'm clueless how to do this :( I know i need to compare each value to the rest and then save it somewhere but I dont know where. Any help will be appriciated :)
To get the keys ordered by number of elements in the corresponding list, you could do:
ascending = sorted(GNR, key=lambda x: len(GNR[x]))
# ascending is ['billy', 'cilla', 'dan', 'anna']
for key in ascending:
li = GNR[key]
# print them etc.

Resources