I have a table like :
ColumnA
ColumnB
8.75
J
5.05
T
6.1
T
8.5
J
I want to sum ColumnA data where ColumnB = J and show it in one of the RDLC textboxes.
What I should write in the Expression Field?
You can use the following expression.
=Sum(IIf(Fields!ColumnB.Value, 1) = "J", CDbl(Fields!ColumnA.Value), 0)
Use IIF( expr truepart,falsepart) to determine if the value is J, and Sum() to calculate the sum.
Related
What's the best way to check if weight are between the range using the If condition?
Ex:
If textbox.text (between) value X - value Z then
You can use standard equal operators like this:
If (Val(TextBox.Text) >= ValueX) And (Val(TextBox.Text) <= ValueZ) Then
' etc...
Val function extracts numbers from string.
I would like to ask how to use Query function where one of the cell contains multiple comma separated values
For example:-
To pull col2 values when Col 1 is B, it would be straightforward.
Col 1
Col 2
A
1
B
2
C
3
D
4
=QUERY(A1:B3,"select B where A = '"&D3&"' ",0)
D3 cell value is B
Similar to how we have IN clause in SQL, I would like to pull data from col 2 when col1 values are B,C,D.
Would it be possible to concatenate the results in one row as well?
Try this one:
=join(", ", QUERY(A1:B4,"select B where "&CONCATENATE("A = '", join("' or A = '", SPLIT(D4, ",")), "'"),0))
Where D4 = B,C,D
Sample Output:
Note:
The values on column B below are the value of the formula:
CONCATENATE("A = '", join("' or A = '", SPLIT(D4, ",")), "'"),0))
Since there was no in statement in sheets query (not that I have encountered), what I did was split those said values in column D and have them format like the multiple or statements which are equal to a single in statement. This is a workaround and should do what you wish to achieve.
I have performed a stratified sample on a multi-label dataset before training a classifier and want to check how balanced it is now. The columns in the dataset are:
|_Body|label_0|label_1|label_10|label_100|label_101|label_102|label_103|label_104|label_11|label_12|label_13|label_14|label_15|label_16|label_17|label_18|label_19|label_2|label_20|label_21|label_22|label_23|label_24|label_25|label_26|label_27|label_28|label_29|label_3|label_30|label_31|label_32|label_33|label_34|label_35|label_36|label_37|label_38|label_39|label_4|label_40|label_41|label_42|label_43|label_44|label_45|label_46|label_47|label_48|label_49|label_5|label_50|label_51|label_52|label_53|label_54|label_55|label_56|label_57|label_58|label_59|label_6|label_60|label_61|label_62|label_63|label_64|label_65|label_66|label_67|label_68|label_69|label_7|label_70|label_71|label_72|label_73|label_74|label_75|label_76|label_77|label_78|label_79|label_8|label_80|label_81|label_82|label_83|label_84|label_85|label_86|label_87|label_88|label_89|label_9|label_90|label_91|label_92|label_93|label_94|label_95|label_96|label_97|label_98|label_99|
I want to group by every label_* column once, and create a dictionary of the results with positive/negative counts. At the moment I am accomplishing this in PySpark SQL like this:
# Evaluate how skewed the sample is after balancing it by resampling
stratified_sample = spark.read.json('s3://stackoverflow-events/1901/Sample.Stratified.{}.*.jsonl'.format(limit))
stratified_sample.registerTempTable('stratified_sample')
label_counts = {}
for i in range(0, 100):
count_df = spark.sql('SELECT label_{}, COUNT(*) as total FROM stratified_sample GROUP BY label_{}'.format(i, i))
rows = count_df.rdd.take(2)
neg_count = getattr(rows[0], 'total')
pos_count = getattr(rows[1], 'total')
label_counts[i] = [neg_count, pos_count]
The output is thus:
{0: [1034673, 14491],
1: [1023250, 25914],
2: [1030462, 18702],
3: [1035645, 13519],
4: [1037445, 11719],
5: [1010664, 38500],
6: [1031699, 17465],
...}
This feels like it should be possible in one SQL statement, but I can't figure out how to do this or find an existing solution. Obviously I don't want to write out all the column names and generating SQL seems worse than this solution.
Can SQL do this? Thanks!
You can indeed do that in one statement but I am not sure the performances will be good.
from pyspark.sql import functions as F
from functools import reduce
dataframes_list = [
stratified_sample.groupBy(
"label_{}".format(i)
).count().select(
F.lit("label_{}".format(i)).alias("col"),
"count"
)
for i in range(0, 100)
]
count_df = reduce(
lambda a, b: a.union(b),
dataframes_list
)
This will create a dataframe with 2 colummns, col which contains the name of the column you are counting, and count the value of the count.
To change it to a dict, I let you read another post.
Here is a solution with single sql, to get all pos and neg counts
sql = 'select '
for i in range(0, 100):
sql = sql + ' sum(CASE WHEN label_{} > 0 THEN 1 ELSE 0 END) as label{}_pos_count, '.format(i,i)
sql = sql + ' sum(CASE WHEN label_{} < 0 THEN 1 ELSE 0 END) as label{}_neg_count'.format(i,i)
if i < 99:
sql = sql + ', '
sql = sql + ' from stratified_sample '
df = spark.sql(sql)
rows = df.rdd.take(1)
label_counts = {}
for i in range(0, 100):
label_counts[i] = [rows[0][2*i],rows[0][2*i+1] ]
print(label_counts)
You can generate sql without group by.
Something like
SELECT COUNT(*) AS total, SUM(label_k) as positive_k ,.. FROM table
And then use the result to produce your dict {k : [total-positive_k, positive_k]}
How to Fnd and Get Data in Datagridview with COndition / Statement in VB.Net?
This the ilustration.
Let's Say The Table Below A Datagridview, with 5 Columns and 5 Rows.
Case In S1
The example of my problem, in S1 :
[1.] Check Ranking A = Ranking B?
[NO]
[2.] Find Ranking B that have Value = Ranking A!
Row-2 [S2]
[3.] Take Nilai B in the Row-2!
[0.8]
[4.] Find the difference between Nilai B in S1 and S2
[0.8 – 0.9 = 0.1]
[5.] Add new Columns and Put 0.1 right there.
And The Result Will be like this :
I dont Understand about Step 2 and Step 3, Somebody please Help Me! I’m confuse because there is no WHERE in VB.Net to make Condition!
Use datagridview filters like this:
YourGridViewBindingSource.Filter = String.Format("YourDBColumn Like ;'*" & FilterValue) & "*'"
Also you can take yourYourGridViewBindingSource
If it's datatable or dataset and use:
Datasource.select(your conditions)
Is there any way to caculate the average of the non zero rows only for a column of data in a table in an RDLC for Microsoft report viewer?
ie
0
0
0
5
5
= 5 not 2
I tried Count( fields.n.value > 0 ) to get the count of non zero rows, but it returned the
count of all rows.
Thanks!
Eric-
Try this:
=Sum(Fields!n.Value > 0) / Sum(IIf(Fields!n.Value > 0, 1, 0))
Notice how the average is computed manually by summing all values then dividing by another sum that mimics a specialized count mechanism.