Is is possible to have a calculated member that shows text instead of numerical values.For instance, classifying customers by the product they bought into Platinum, gold, silver and bronze.
Is it possible to aggregate the data and show it in the cube in this way?
Since you have a Multidimensional cube you write the calculated measures in MDX. You can use the Case function to build a calculation like this which returns text:
CREATE MEMBER CURRENTCUBE.[Measures].[Classification]
AS
Case
When [Measures].[Volume] >= 1 And [Measures].[Volume] < 6 Then "Bronze"
When [Measures].[Volume] >= 6 And [Measures].[Volume] < 11 Then "Silver"
When [Measures].[Volume] >= 11 And [Measures].[Volume] <= 15 Then "Gold"
When [Measures].[Volume] > 15 Then "Platinum"
End;
Related
I was thus to come up with a solution for The column "Loan_Term" which measures the duration of the loan applied for, in months.
Applicants asking for loans with loan terms less than 120 months are given a rating of "Short" under loan tenure. Those with loan terms at least 120 months, but less than 300 months will be rated as "Medium". Applicants asking for loans with loan terms of 300 or more months, will be rated as "Long".
Write a function that takes an applicant's numerical value of months of Loan_Term as an input parameter and returns the respective customer's rating. Create a new attribute "Loan_Tenure" for every applicant in df_loans.
Display df_loans with only the "Loan_Term" and "Loan_Tenure" attributes.
My code is as follows df_loans =df
df_loans.loc[(df_loans.Loan_Term < 120 return "Short" ) | (df_loans.Loan_Term > 120 & < 300 return "Medium") | (df_loans.Loan_Term > 300 return "Long")]. It is wrong and I was wondering is there a way for it to only display this criterion in the table through loc or must i use something else.
for this you can use numpy's select function
df['Loan_Tenure'] = np.select([df_loans.Loan_Term <= 120 ,(df_loans.Loan_Term>120)&(df_loans.Loan_Term<300),(df_loans.Loan_Term >= 300)],['Short','Medium','Long'])
I am looking to compute the avg win odds and avg place odds of horse racing markets
I have tried a CASE expression since averages for WinOdds should only be calculated if Place =1 and averages for PlaceOdds should only be included when Place <= 10
SELECT
CASE WHEN Place = 1 THEN AVG(IndustrySP) AS AvgWinOdds,
CASE WHEN Place <= 10 THEN AVG((IndustrySP - 1.0) / 5) AS AvgPlaceOdds
FROM dbo.GrandNational -- This is the `view` I want to query
I am looking for average odds for win (when Place =1)
and average odds for place (when Place is <= 10)
Should return something like this:
-- AvgWinOdds -- AvgPlaceOdds
-- 6.44 -- 4.22
You must average the CASE expressions:
SELECT
AVG(CASE WHEN Place = 1 THEN IndustrySP END) AS AvgWinOdds,
AVG(CASE WHEN Place <= 10 THEN (IndustrySP - 1.0) / 5 END) AS AvgPlaceOdds
FROM dbo.GrandNational
I am building a report in Report Builder for SSRS. My Data looks like:
My Column Chart is grouped by Organization, with a series group of Category and each of the 6 categories will apply to each Organization.
I'd like to add an additional Line Series to show an overall average of all categories for each Organization.
Can anyone suggest the way to achieve this? Do I need a new calculated field in SSRS, should I enhance my SQL query to get the calculation done there?
My SQL Query is:
select OrganizationUnitID,Category,AVG(NumericValue) as average
, case
when AVG(NumericValue) <= 1 then 0
when AVG(NumericValue) > 1 and AVG(NumericValue) <= 2 then 50
when AVG(NumericValue) > 2 and AVG(NumericValue) <= 3 then 75
when AVG(NumericValue) > 3 then 100 end
as percentage
from SurveyMetricView
group by OrganizationUnitID,Category
order by OrganizationUnitID
The desired result is this chart:
Thanks in advance for any advice.
This is a possible solution for the requeriment you posted.
Add textbox to your surface, just put it in any place in your report.
Set the following expression to the textbox.
=Avg(Fields!percentage.Value, "DataSetName")
Add the below expression to the series. Note in the expression that I am referencing the Textbox49 since it's the name of the textbox that I added to the report before and It contains the average of all values.
=ReportItems!Textbox49.Value
Change the chart type for the series you've added to Line Chart.
It will preview this:
You can set the Visibility property of the textbox to hidden = true
if you don't want it appears in your report.
Let me know if this was helpful
Thanks for the pointers.
In the end what I did was to create a new dataset with the following query to calculate the overall average for each Organization, essentially selecting distinct organization:
declare #st_date datetime;
declare #en_date datetime;
set #st_date = (#st_datein);
set #en_date = (#en_datein);
Select Distinct
SurveyMetricView.OrganizationUnitID,
Avg(SurveyMetricView.NumericValue) As average,
Case When Avg(SurveyMetricView.NumericValue) <= 1 Then 0
When Avg(SurveyMetricView.NumericValue) > 1 And
Avg(SurveyMetricView.NumericValue) <= 2 Then 50
When Avg(SurveyMetricView.NumericValue) > 2 And
Avg(SurveyMetricView.NumericValue) <= 3 Then 75
When Avg(SurveyMetricView.NumericValue) > 3 Then 100 End As percentage
From
SurveyMetricView
where
OrganizationUnitID in (#OrganizationUnit)
and ClosedDateTime >= #st_date
and ClosedDateTime <= #en_date
Group By
SurveyMetricView.OrganizationUnitID
Order By
SurveyMetricView.OrganizationUnitID
My report has 3 families (grouped by family.) I need to display the mtd, ytd, lytd per family AS:
household--mtd--ytd--lytd
family1 20 500 4000
family2 300 70 6000
family3 60 8880 977400
The only date field is called paiddate (datetime.)
If I use an IF statement datedif("yyyy",-1,currentdate() then.... I get zeros for certain families due to the grouping. I think I may need a group selection formula or a new group for mtd, ytd and lytd?
Create these formula fields and add them to your Details section. Group and summarize as desired.
//{#MonthToDate}
If {table.paiddate} IN MonthToDate Then
{table.revenue}
Else
0
//{#YearToDate}
If {table.paiddate} IN YearToDate Then
{table.revenue}
Else
0
//{#OtherPeriodToDate}
//no clue what LYTD means; demonstrate a custom-range instead; substitute actual logic for Date(YYYY,MM,DD)
If {table.paiddate} IN Date(YYYY,MM,DD) TO Date(YYYY,MM,DD) Then
{table.revenue}
Else
0
I need to filter the measure values as
MeasureA MeasureB
10 10
15 15
5 20
20 20
Here I need to get only the measures are not equal, I am using filter function as but not working
Select Filter({[Measures].[A],
[Measures].[B]},
([Measures].[A]-
[Measures].[B])=0)
on 0
from [Cube]
Expected result set
MeasureA MeasureB
5 20
What am I missing?
Try using a dimension instead of your measures for the first part of the filter statement. Assuming you are querying products then your query might look like:
select {[Measures].[A],[Measures].[B]} on columns,
filter ({[Products].Members},[Measures].[A] = [Measures].[B]) on rows
from [Sales Cube]
You might want to try creating a calculated field in the DSV for this Fact table...
CASE
WHEN MeasureFieldA != MeasureFieldB THEN 1
ELSE 0
END
Then you can create a "fact dimension" and have this calculated field as an attribute to be used in your queries or calculated measures.