I am looking to create a second column which counts all the columns with a number >= 2.
Total
2.03
2.00
2.00
1.38
1.33
1.32
1.21
Expected result
Total Count column
2.03 3
2.00
2.00
1.38
1.33
1.32
1.21
I have looked at SUMIF and COUNTIF
=Sum(IIf(Fields!Total.Value >= "2" , 1, 0)
But i just get the SSRS cannot create report error.
Can anyone help? thanks
Related
I would like to know that how would I get a data like, Date in first column and all stations ID in second column and all respective values of Average Wind speed, Sunshine duration and all and below that, Next date in next row and all stations in column beside this. I have data as below,
Stations_ID Date Average windspeed (Beaufort) sunshine duration average cloud cover
0 102 2016-01-01 6.8 5.733 NaN
1 164 2016-01-01 1.6 0.000 8.0
2 232 2016-01-01 2.0 0.000 7.8
3 282 2016-01-01 1.2 0.000 7.8
4 183 2016-01-01 2.9 0.000 7.8
... ... ... ... ... ...
164035 4271 2021-12-31 6.7 0.000 7.6
164036 4625 2021-12-31 7.1 0.000 7.3
164037 4177 2021-12-31 2.6 4.167 3.9
164038 4887 2021-12-31 4.7 5.333 3.8
164039 4336 2021-12-31 3.4 0.000 7.4
I have used below line of code,
df_data_3111 = pd.DataFrame(df_data_311.groupby(['Date','Stations_ID'])['Minimum Temperature'])
But this does not work.
I have financial data that I want to categorise (using NTILE()) by two columns that contain percentage values (risk, debt_to_assets). My end goal is that I want to aggregate some other column (profit) by the two categories, but that's not related to my issue at hand. The data looks something like this:
profit
risk
debt_to_assets
7000
0.10
0.20
1000
0.40
0.70
3000
0.15
0.50
4000
0.30
0.30
2000
0.20
0.60
The issue I'm trying to solve is that I want the categories to be nested such that, in addition to the population distribution being uniform, the categories of the inner quantile are consistent across the categories of the outer quantile in terms of the range that defines the categories (i.e. I want the min and max value for the inner categories (x0, y0), (x1, y0), (x2, y0), ... to all be the same or as close as possible, where the x's are the outer category and the y's are the inner category).
Ideally if I were to aggregate the columns used for the NTILE() function (using 3 inner categories and 3 outer categories for example) I'd want a table that resembles the following:
risk_cat
dta_cat
min_risk
max_risk
min_dta
max_dta
count
1
1
0.00
0.33
0.00
0.33
100
1
2
0.00
0.33
0.34
0.67
100
1
3
0.00
0.33
0.68
1.00
100
2
1
0.34
0.67
0.00
0.33
100
2
2
0.34
0.67
0.34
0.67
100
2
3
0.34
0.67
0.68
1.00
100
3
1
0.68
1.00
0.00
0.33
100
3
2
0.68
1.00
0.34
0.67
100
3
3
0.68
1.00
0.68
1.00
100
These are the solutions I've tried but they only solve part of the issue, not the whole thing:
SELECT *,
NTILE(3) OVER (
ORDER BY risk
) AS risk_cat,
NTILE(3) OVER (
ORDER BY debt_to_assets
) AS dta_cat
FROM my_table
This would result in an aggregated table like this:
risk_cat
dta_cat
min_risk
max_risk
min_dta
max_dta
count
1
1
0.00
0.33
0.00
0.33
10
1
2
0.00
0.33
0.34
0.67
55
1
3
0.00
0.33
0.68
1.00
180
2
1
0.34
0.67
0.00
0.33
135
2
2
0.34
0.67
0.34
0.67
140
2
3
0.34
0.67
0.68
1.00
100
3
1
0.68
1.00
0.00
0.33
130
3
2
0.68
1.00
0.34
0.67
110
3
3
0.68
1.00
0.68
1.00
40
The problem is that the count across the two categories isn't uniform.
WITH outer_cat AS (
SELECT *,
NTILE(3) OVER (
ORDER BY risk
) AS risk_cat
FROM my_table
)
SELECT *,
NTILE(3) OVER(
PARTITION BY risk_cat
ORDER BY debt_to_assets
) AS dta_cat
FROM outer_cat
The aggregated table for this might resemble the following:
risk_cat
dta_cat
min_risk
max_risk
min_dta
max_dta
count
1
1
0.00
0.33
0.10
0.70
100
1
2
0.00
0.33
0.71
0.90
100
1
3
0.00
0.33
0.91
1.00
100
2
1
0.34
0.67
0.05
0.35
100
2
2
0.34
0.67
0.36
0.60
100
2
3
0.34
0.67
0.61
0.90
100
3
1
0.68
1.00
0.00
0.25
100
3
2
0.68
1.00
0.26
0.50
100
3
3
0.68
1.00
0.51
0.80
100
The problem this time is that the min and max values for the inner category vary to much across the outer category.
SELECT *,
NTILE(9) OVER(
ORDER BY risk, debt_to_assets
) AS dual_cat
FROM my_table
The aggregated table for this looks something like the following:
dual_cat
min_risk
max_risk
min_dta
max_dta
count
1
0.00
0.11
0.55
1.00
100
2
0.12
0.22
0.35
1.00
100
3
0.23
0.33
0.15
1.00
100
4
0.34
0.44
0.40
1.00
100
5
0.45
0.55
0.10
1.00
100
6
0.56
0.66
0.10
0.95
100
7
0.67
0.77
0.05
1.00
100
8
0.78
0.88
0.20
1.00
100
9
0.89
1.00
0.00
1.00
100
This was just a last attempt at a solution after the previous two didn't work. This attempt didn't capture any of the behaviour that I was looking for.
Is there a solution to my problem that I'm not seeing?
i have the below sample of data, and i need to create a function that will take a sales date and compare it with the below dates and returns the discount name & percentage, but as below the discount dates are not unique and some times overlaps, so in case the date falls in two different discounts names it has to return the highest duplicate discount name based on the percentage in case the sale date falls in more than one.
Discount Name Start Date End Date Percentage
0 First 2020-07-24 2020-11-25 0.10
1 First 2020-09-13 2020-10-29 0.10
2 First 2020-12-07 2020-12-10 0.10
3 First 2020-12-28 2021-01-19 0.10
4 First 2020-06-14 2020-06-14 0.10
5 Second 2020-06-16 2020-06-18 0.15
6 Second 2020-06-21 2020-06-22 0.15
7 Second 2020-06-22 2020-06-23 0.15
8 Second 2020-07-07 2020-07-08 0.15
9 Third 2020-06-02 2020-06-12 0.20
10 Third 2020-05-19 2020-06-01 0.20
11 Third 2020-05-06 2020-05-17 0.20
12 Third 2020-04-30 2020-05-03 0.20
Screen Shot of Dataframe
i truly hope that someone can help me on this. thanks
This function should do the trick
def discout_rate(df, sales_date):
return df[(df['Start Date'] <= sales_date) & (df['End Date'] >= sales_date)]['Percentage'].max()
The sales_date should be of type datetime.datetime and the columns Start Date and End Date too.
We are replacing an old system with SSAS in SQL Server 2016. An existing report that needs to be replaced in the new system looks like this:
From Date To Date Days Cash Settled Rate (%) Interest
2017-01-01 2017-01-03 3 1000.00 1500.00 3.13 0.39
2017-01-04 2017-01-04 1 1100.00 1500.00 3.13 0.13
2017-01-05 2017-01-05 1 1100.00 1600.00 3.33 0.15
The underlying data would be this:
Date Cash Settled Rate (%) Interest
2017-01-01 1000.00 1500.00 3.13 0.13
2017-01-02 1000.00 1500.00 3.13 0.13
2017-01-03 1000.00 1500.00 3.13 0.13
2017-01-04 1100.00 1500.00 3.13 0.13
2017-01-05 1100.00 1600.00 3.33 0.15
The report basically groups all rows where Cash, Settled, and Rate are the same. I found a similar issue in this question but it is for SQL. Right now I use that for the report but would like to use MDX for better aggregation since the daily values consist of many detail rows.
In a twist to the above it is also possible that Settled, Rate, or all three (plus the derived Interest) are NULL.
I believe this issue is referred to as the Gaps and Islands problem. Has anyone any ideas on how to solve it in MDX?
I am running into an issue with a simple SQL math operation of qty * price is returning an incorrect value.
This is SQL server 2005. Compatibility is set to 80 for 2000 SQL server.
Any help on understanding why I am having the problem shown below
For example:
Transaction Table:
id price qty
1 2.77 20.00
1 2.77 25.00
1 2.77 10.00
2 0.10 50.00
2 0.10 80.00
3 0.10 50.00
3 0.10 60.00
SQL
Select id, price, qty, (qty * price) from transact
The actual problem was this and it was my fault :(
Select id, CAST(price AS DECIMAL(5,2)), qty, (qty * price) from transact
Returns the following:
id price qty Total
1 2.77 20.00 55.400000 Correct
1 2.77 25.00 69.250000 Correct
1 2.77 10.00 27.700000 Correct
2 0.10 50.00 4.800000 Should be 5.0000
2 0.10 80.00 7.680000 Should be 8.0000
2 0.10 50.00 5.050000 Should be 5.0000
2 0.10 60.00 6.060000 Should be 6.0000
3 39.00 1.00 39.000000 Correct
3 39.00 2.00 78.000000 Correct
3 39.00 3.00 117.000000 Correct
You price is being rounded somewhere. The select you are running is not showing the actual price.
select round(0.096, 2) price, 0.096 * 50.00 total
Result:
price total
0.10 4.80000