hoping to get some help here. I have a report that shows 4 fields: current YTD sales, previous YTD sales, the difference between the 2 in dollars, and the difference between the 2 in percent. I'm running into a divide by 0 error and the value of "NaN" as the value for the percent field. I get the divide by 0 error when I have a value in the current YTD ("OrderInfoConstruction") but 0 in the previous YTD ("OrderInfoClosedConstruction"), since my expression for the % field is:
=(Sum(Fields!PRICE_EXT.Value, "OrderInfoConstruction") -
Sum(Fields!PRICE_EXT.Value, "OrderInfoClosedConstruction")) /
Sum(Fields!PRICE_EXT.Value, "OrderInfoClosedConstruction")
and the value of "Sum(Fields!PRICE_EXT.Value, "OrderInfoClosedConstruction") is 0 (the previous YTD value). For the NaN value issue, it's the same expression, but in this case, BOTH current and previous YTD's are 0. How can I have it NOT divide if the value is 0 to solve the divide by 0 error and what is a NaN and how can I have it just show "0" instead? I've found some help on this but have NO idea how to take the IIF statement below and adapt it for my statement above?
=IIf(Fields!SomeField.Value = 0, 0, Fields!SomeOtherField.Value / IIf(Fields!SomeField.Value = 0, 1, Fields!SomeField.Value))
thanks in advance for the help!!!
If you want to display 0 for both 0/0 and #/0, you just need to check the denominator value for zero. Basically IIf(PrevYTD = 0, 0, (CurrYTD - PrevYTD) / PrevYTD), or with your actual fields:
=IIf(Sum(Fields!PRICE_EXT.Value, "OrderInfoClosedConstruction") = 0, 0,
(Sum(Fields!PRICE_EXT.Value, "OrderInfoConstruction") -
Sum(Fields!PRICE_EXT.Value, "OrderInfoClosedConstruction")) /
Sum(Fields!PRICE_EXT.Value, "OrderInfoClosedConstruction"))
Also, NaN stands for not a number, and 0/0 is one operation that produces it.
Related
I have to do a calculation that required dividing a negative number by a positive number.
I'm using SQLite and when I put in SELECT -10 / 500 then output is 0.
Why is that the case?
Because, SQL considers both -10 and 500 as Integers and so it gives the output as an integer here. You can change either of them or both as decimal and by doing so, you will get the desired result.
I have a pandas dataframe in python and I'm trying to modify a specific value in a particular row. I found a solution to this problem Set value for particular cell in pandas DataFrame using index, but it is still generating the SettingWithCopy error.
The name of the data frame is internal_df and it has columns 'price', 'visits', and 'orders'. Specifically, I want to add the number of orders and visits to a lower price point if we don't have a sufficient number of visits (100 in this example). Note that below the variable 'price' is a float, and the data types for 'price' within the internal_df data frame is float, while price and orders are ints.
if int(internal_df[internal_df['price']==price]['visits']) < 100:
for index, row in internal_df.iterrows():
if float(row['price']) > price:
internal_df.ix[internal_df['price'] == price, 'visits'] = internal_df.ix[internal_df['price'] == price, 'visits'] + row['visits']
internal_df.ix[internal_df['price'] == price, 'orders'] = internal_df.ix[internal_df['price'] == price, 'orders'] + row['orders']
Here is a sample of the data
price visits sales
0 1399.99 2 0
1 169.99 2 0
2 99.99 1 0
3 99.99 1 0
4 139.99 1 0
5 319.99 1 0
6 198.99 1 0
7 119.99 1 0
8 39.99 1 0
9 259.98 1 0
Does anyone have any suggestions, or should I just ignore the error?
Brad
Note that .ix is deprecated because it indexes by position or by label, depending on the data type of the index. Use .loc or .iloc instead.
This SettingWithCopyWarning might originate from a "get" operation several lines of code above what you've provided. A quick fix might be to find where internal_df is first assigned, and to add .copy() to the end of the assignment statement. For example, if you have internal_df = df[df['colname'] <= value], change that to internal_df = df[df['colname'] <= value].copy() and hopefully that resolves the error.
Also, I think you can do what you're trying to do without a for loop, which would be faster and more readable!
I have a column with around 20k values. I've used the following function in pandas to display their counts:
weather_data["snowfall"].value_counts()
weather_data is the dataframe and snowfall is the column.
My results are:
0.0 12683
M 7224
T 311
0.2 32
0.1 31
0.5 20
0.3 18
1.0 14
0.4 13
etc.
Is there a way to:
Display the counts of only a single variable or number
Use an if condition to display the counts of only those values which satisfy the condition?
I'll be as clear as possible without having a full example as piRSquared suggested you to provide.
value_counts' output is a Series, therefore the values in your originale Series can be retrieved from the value_counts' index. Displaying only the result of one of the variables then is exactly slicing your series:
my_value_count = weather_data["snowfall"].value_counts()
my_value_count.loc['0.0']
output:
0.0 12683
If you want to display only for a list of variables:
my_value_count.loc[my_value_count.index.isin(['0.0','0.2','0.1'])]
output:
0.0 12683
0.2 32
0.1 31
As you have M and T in your values, I suspect the other values will be treated as strings and not float. Otherwise you could use:
my_value_count.loc[my_value_count.index < 0.4]
output:
0.0 12683
0.2 32
0.1 31
0.3 18
Use an if condition to display the counts of only those values which satisfy the condition?
First create a new column based on the condition you want. Then you can use groupby and sum.
For example, if you want to count the frequency only if a column has a non-null value. In my case, if there is an actual completion_date non-null value:
dataset['Has_actual_completion_date'] = np.where(dataset['ACTUAL_COMPLETION_DATE'].isnull(), 0, 1)
dataset['Mitigation_Plans_in_progress'] = dataset['Has_actual_completion_date'].groupby(dataset['HAZARD_ID']).transform('sum')
I tried to search this problem and unlucky to solve.
I have a generated report using the rdlc, now, I want to sum all the positive numbers not including the negative in rdlc coding way.
Credit
------
3
3
3
3
3
3
2
-3
-2
------
Total: 20
So, the main point is ignore the negative and sum the positive numbers. so far this what I have tried and this not the solution of my problem.
=IIF(Fields!creditUnit.Value > 0, Sum(Fields!creditUnit.Value), 0)
Anybody can help me?
UPDATE:
This was my temporary solution, since my generated report is good for only one page. I create a parameter for Total
var total = creditsList.Where(c => c.HasValue && c.credit > 0).Sum(c => c.credit.Value);
var totalParam = new ReportParameter("total", total);
I hope that one of you guys can help me in what would be the solution in rdlc coding way to sum all the positive numbers.
UPDATE:
I included the vb.net because the way the coding of rldc is VB syntax.
try
=Sum(IIF(Fields!creditUnit.Value > 0, Fields!creditUnit.Value, 0))
I know its to late but this will work for me
if column have only integer then following expression can be use.
=Sum(IIf((Fields!creditUnit.Value>0), CInt(Fields!creditUnit.Value), 0))
But for decimal or integer and decimal (both) following expression can be use.
=Sum(IIf((Fields!creditUnit.Value>0),CDbl(Fields!creditUnit.Value),0.0))
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.