Count rows with value Yes in column Winforms - winforms

I have a Winform with 3 column access table. I find total number of rows in access table as below
lblnoofrow.Text = "Total no of rows :- " + tbl.Rows.Count.ToString()
Now I have to find number of rows with Yes in column named Completed. Please help.
Thanks

If you have already retrieved that table and you have it at your disposal in your code, you could count the rows with the YES string inside a column with this code
lblnoofrow.Text = "Total no of rows :- " +
tbl.AsEnumerable().Count(x => x.Field<string>("Completed") == "Yes");
Here I assume that your column is of type string, but if it is a YesNo field then change the <string> to <bool> and compare against true/false
lblnoofrow.Text = "Total no of rows :- " +
tbl.AsEnumerable().Count(x => x.Field<bool>("Completed") == true);
(well the compare against true is not really needed but in this case I think it makes things more readable)

Related

How to separate comma separated and where condition in LINQ

I have a giftcardamounts in database table.
Column contains dollar and comma separated values.
There are 40 rows.
Ex:
row 1: giftcardamounts : ($10,$20,$30,$40,$50)
row 2: giftcardamounts : ($100,$200,$30,$40,$50)
row 3: giftcardamounts : ($10,$20,$300,$400,$500)
...etc
From frontend there is an input is giftcardselectedamount
Ex: giftcardselectedamount=500
Based on this input amount in need to write LINQ query on dollar and comma separated list of Values.
Please help me how to write this.
Like commenters have noted, you should show some effort in reaching to an answer. Also your question isn't quite clear. Are you asking to return the row with a matching amount? If so you can try the following approach, which returns the first row that contains the dollar amount specified:
void Main()
{
var data = new[] {
"$10,$20,$30,$40,$50",
"$100,$200,$30,$40,$50",
"$10,$20,$300,$400,$500"};
var giftcardSelectedAmount = 500M;
var matchingRow = data.FirstOrDefault(x => x
.Split(',')
.Any(v => decimal.Parse(v, NumberStyles.Currency) == giftcardSelectedAmount));
Console.WriteLine(matchingRow);
}
I can easily modify this answer to return all matching rows, a count of occurrences, or a count of rows with occurrences. Let me know if you need any of these modifications and I can modify my answer to add these.

ISBLANK(...) = FALSE even thought the cell is blank in google sheet

Hi everyone,
I have 2 tables, 3rd column for Table 1 is Value 1 and 3rd column for Table 2 is Value 2. I combined these 2 tables by expanding both tables first so that all the columns are aligned as shown in the screenshot above (Column E to Column H).
The formula in all the yellow cells are:
Cell E4 : =QUERY(A4:C10,"Select A,B,C,' ' label ' ' 'Value 2' ")
Cell E12 : =QUERY(A12:C20,"Select A,B,' ',C label ' ' 'Value 1' ")
Cell K7 : =QUERY({E5:H10;E13:H17},"Select * where Col1 is not null",0)
Cell P7 : =ArrayFormula(IF(ISBLANK(M7:M12),100,M7:M12))
In column P, I want to return 100 as Value 1 if the cells in Column M is blank. So by right I should get 2,34,55,100,100,100 in column P but right now the formula still return 3 blank cells.
I suspect that is because the QUERY function that I used before which make the cell is not blank although it seems like still a blank cell. May I know is there any trick that I can use to find the blank cells in column M and column N (preferably don't touch the QUERY formula) since ISBLANK() is not working in this case?
Any help or advise will be greatly appreciated!
Edited
makes sense. you cant use ISBLANK because cell is not blank. remember that QUERY inserted an empty space.
try:
=ARRAYFORMULA(IF(ISBLANK(TRIM(M7:M12)), 100, M7:M12))
ISBLANK is so sensitive that it will detect even residue from TRIM
update:
=ARRAYFORMULA(IF(TRIM(M7:M12)="", 100, M7:M12))

google sheet : How to vlookup by matching value in between max and min?

I have 2 sheets like this :
In that 2nd sheet, i want to lookup the id (S/M/L/XL) by checking if value is in between the Min value and Max value. So the goal is to have something like that 2nd sheet where in 'level' column, i need to put a formula so it will check the value is between what range so then it will retrieve the correct 'id' from 1st sheet.
the rule is if the value is >= minvalue and < max value
How can i do this ?
Thanks
use:
=INDEX(IF(A9:A="",,VLOOKUP(A9:A, {C2:C5, A2:A5}, 2, 1)))
Your first table, has overlapping values, so I suggest you think better about the rules you want to apply.
For example, 1, according your table can match both "S" and "M" , same for 3, which can be "M" or "L".
Once you have resolved that, you can use the QUERY function.
Example:
=QUERY($A$2:$D$5,
"select A,D where C<="&A2&" AND D >="&A2&" ORDER BY D DESC LIMIT 1 ")
Working solution can be found here:
https://docs.google.com/spreadsheets/d/1oLVwQqihT_df2y_ZQnfx7By77HnKSFz0bcbOzMuWqOM/edit?usp=sharing
Rather than have min and max columns, you could just use one column to list incremental values that determine the next size, and use vlookup() with a sort option of true - this avoids overlapping values:
=arrayformula({"level";if(A2:A<>"",VLOOKUP(A2:A,{Source!C:C,Source!A:A},2,1),)})

Inserting rows to dataframe on multiple indices based on conditions in python-pandas

I have a dataframe like this
Whenever I see an instance where start is followed by stop and DURATION column is 0, I need to insert a row after that (at 4th and 8th row in this case), which should contain pretty much the same values of its previous row, but the event column should be denoted by E1.
I need to get something like this
How can I achieve this since multiple indices can have the values with START-STOP and duration as 0?
Thanks in advance!
If you always have a sequence 'start-stop' (stop is always followed by start), it will work:
df.loc[(df['DURATION'] == 0) & (df['event'] == 'stop'), 'event'] = 'E1'
What means: Put 'E1' in column 'event' for each row which has 0 in column 'DURATION' and 'stop' in column 'event'.

Total length off all characters in all columns of each row

I'm new to SQL Server so I apologize if my question seems too easy. I tried finding and answer on my own, but I'm failing miserably. I am trying to create a query which will return total size on the drive of each row in the table.
i thought about using dbcc showconting but it doesn't work for varchar(max) which appears in my table. Also, it doesn't return size for each row, but rather the average, max and min size. My reading so far suggests that it is not possible to get query that could show the size of each individual row in the table so I decided to settle for the total length of all characters in each column in each row. Indirectly it will give me idea about the size of each row.
I have a table with some varchar(500) and varchar(max) columns. I noticed that some of the rows are a lot bigger than others.
What I need is top 1000 longest rows in the table, preferably in an output showing two columns:
Column 1 showing EntryID
Column 2 showing total length of the characters in all columns together for that record (eg total length of the characters in the column 1 + total length of the characters in the column 2 + column3 + column4 etc...) It would be great if this could be aliased RowLength.
What I tried so far is:
SELECT TOP 1000
(LEN(columnname1) + LEN(columnname2) + LEN(columnname3) + LEN(columnname4)) as RowLength,
FROM dbo.tablename
ORDER BY Length Desc
It works, but it doesn't show entry ID corresponding to the total length of all characters in the row. How do I add it?
It also doesn't show the alias for the column showing number of characters in the row.
Could you please suggest how I can change the query to get the expected outcome? I'll be very grateful for any suggestions.
it doesn't show EntryID corresponding to the total length of all
characters in the row. It also doesn't show the alias for the column
showing number of characters in the row.
You have not specified an alias, so what should it show? You also haven't selected EntryID. If you want the longest 1000 rows you have to order by the length:
SELECT TOP 1000
EntryID,
Length = LEN(columnname1) + LEN(columnname2) + LEN(columnname3) + LEN(columnname4)
FROM dbo.tablename
ORDER BY Length DESC
SELECT TOP 1000 EntryID,
(LEN(columnname1) + LEN(columnname2) + LEN(columnname3) + LEN(columnname4)) AS RowLength,
FROM dbo.tablename
ORDER BY EntryID

Resources