I have a crosstab report that calculates for failure rates for my products ; it has two measures (PASSCOUNT, FAILCOUNT) and a calculation FAILRATE (FAILCOUNT/PASSCOUNT+FAILCOUNT)
The report layout looks thusly:
OEM
MODEL
TESTYEAR TESTMONTH PASSCOUNT FAILCOUNT FAILRATE
When I select the Total icon, it logically adds up each of the columns like so
2012 OCT 7547 697 0.08
NOV 9570 373 0.04
DEC 1879 107 0.05
------------------------
Total 18996 1177 0.17
My user however wants TOTAL FAILRATE to be
TOTAL FAILCOUNT/(TOTAL PASSCOUNT+TOTAL FAILCOUNT)
which translates to
1177 / (18996+1177) = 0.058
How can I create this custom total in the report? I am reading about creating a Query calculation but I am not clear this is the right approach.
Cognos Report Studio 8.4 IBM DB2 UDB
You can indeed. There a couple methods.
In your report query you have the individual query items that comprise your desired calculation working fine(PASSCOUNT, FAILCOUNT, etc...). You can create a new data item/expression in that same query item list and edit the definition. In the left hand side you can choose to use columns from your original db data source but there is another pane you can select to actually re-use other query items/calculations you have definied in that same query (PASSCOUNT FAILCOUNT FAILRATE). Cognos knows that when you create an expression using other columns in the same query to resolve those query items first in order to resolve your calculation that is dependent upon them. You want to make sure your calculated/derived column is listed after the other dependent query items(Actually this may not matter but it makes sense when looking at it). Also I believe you will have to set the the failure rate query item/expression to "Calculated" as its aggregate method.
The summary line might/might not be a bit trickier. Not having report studio right in front of me it might be smart enough when you add the totals section to the list report and use your new failure rate expression... to extend the correct calculation or you may have to use another method to do the summary which is a report expression.
You create a report expression not in the query but on the gui page of the report(its in the toolbox along side tables, singltons etc...). It has an expression builder just like in the query but you will notice the function set is different because it is being done after the query runs and as the results come back so simple things like you are doing is fine which is just math but you will notice other database functions are not available on report expressions simply because they are occuring in the html output and not during the query run against the database.
Hope this helps. In summary you are creating a calculated column based on the summarized calculations of other columns in the same query/result set. This would be in theory the same as this SQL statement which will not work because SQL does not allow this directly but hope it helps explain what cognos is doing.
Select 1+2 As FAILCOUNT, 2+3 AS PASSCOUNT, (FAILCOUNT/PASSCOUNT+FAILCOUNT) AS FAILRATE From SOMETABLE
-- Cognos is able to use the results other aggregate calculated columns in the same query and if you gen sql you can see how it arranges the SQL to do this.
Thanks,
Tim
It's important to pick the right total in Crosstab.
When you add the total row, make sure you pick Automatic Summary:
This option will make sure the aggregation is determined individually by each query data item.
If it still does not give you expected result, then on the query explorer, pick the query that is being used on the crosstab, and on the FAILRATE data item, pick the calculated option (on the properties panel):
In the crosstab reports what happens is the columnar data is rendered first n then the row level data, so this is the cause of your problems ..To resolve this click on the List Column Title 'FAILRATE' & assign it a Solve Order = 1, as long as the solve order of total is NULL..The trick is that the Solve order would control the calcuation of FAILRATE after all others are done.
Related
I have a column of data [Sales ID] that bringing in duplicate data for an analysis. My goal is to try and limit the data to pull unique sales ID's for the max day of every month in the analysis only (instead of daily). Im basically trying to get it to only pull in unique sales ID values for the last the day of every month in the analysis ,and if the current day is the last day so far then it should pull that in. So it should pull in the MAX date in any given month. Please how do i write an expresion with the [Sales ID] column and [Date ] column to acieve this?
Probably the two easiest options are to
1) Adjust the SQL as niko mentioned
2) Limit the visualization with the "Limit Data Using Expression" option, using the following:
Rank(Day([DATE]), "desc", Month([DATE]), Year([DATE])) = 1
If you had to do it in the Data on Demand section (maybe the IL itself is a usp or you don't have permission to edit it), my preference would be to create another data table that only has the max dates for each month, and then filter your first data table by that.
However, if you really need to do it in the Data on Demand section, then I'm guessing you don't have the ability to create your own information links. This would mean you can't key off additional data tables, and you're probably going to have to get creative.
Constraints of creativity include needing to know the "rules" of your data -- are you pulling the data in daily? Once a week? Do you have today's data, or today - 2? You could probably write a python script to grab the last day of every month for the last 10 years, and then whatever yesterday's date was, and throw all those values into a document property. This would allow you to do a "Values from Property".
(Side Note: I want to say you could also do it directly in the expression portion with something like an extremely long
Date(DateTimeNow()),DateAdd("dd",-1,Date(Year(DateTimeNow()), Month(DateTimeNow()), 1))
But Spotfire is refusing to accept that as multiple values. Interestingly, when I pull the logic for a StringList property, it gives this: $map("${udDates}", ","), which suggests commas are an accurate methodology, but I get an error reading "Expected 'End of expression' but found ','" . Uncertain if this is a Spotfire issue, or related to my database connection)
tl;dr -- Doing it in the Data on Demand section is probably convoluted. Recommend adjusting in SQL if possible, and otherwise limiting in the visualization
I am trying to generate an Access database with information which is currently in endless sheets and tables in Excel.
I would like to know if there is any way to add a field to one table which is a calculation (average value) based on several other cells.
I need to calculate the running 6 months average value of another field which contains 1 value per month.
Hopefully the previous image shows what I mean.
What is the best approach to import this functionality into access?
You wouldn't normally store a calculated field in Access, you would run a query that provides you the calculation on the fly.
Without seeing your data structure it is impossible to tell you how to calculate the answer you need, but you would need your data correctly normalised in order to make this simple.
Due to performance issues I need to remove a few distinct counts on my DAX. However, I have a particular scenario and I can't figure out how to do it.
As example, let's say one or more restaurants can be hired at one or more feasts and prepare one or more menus (see data below).
I want a PowerPivot table that shows in how many feasts each restaurant was present (see table below). I achieved this by using distinctcount.
Why not precalculating this on Power Query? The real data I have is a bit more complex (more ID columns) and in order to be able to pivot the data I would have to calculate thousands of possible combinations.
I tried adding to my model a Feast dimensional table (on the example this would only be 1 column of 2 rows). I was hoping to use that relationship to be able to make a straight count, but I haven't been able to come up with the right DAX to do so.
You could use COUNTROWS() combined with VALUES().
Specifically, COUNTROWS() will give you the count of rows in a table. That means COUNTROWS is expecting a table is input. Here's the magic part: VALUES() will return a table as results, and the table it returns are the distinct values in the table/column that you provide as the argument for VALUES().
I'm not sure if I'm explaining it well, so for the sample data you provided, the measure would look like this (assuming the table is named Table1):
Unique Feasts:=COUNTROWS(VALUES('Table1'[Feast Id]))
You can then create a pivot table from Powerpivot, and drag Restaurant Id into Rows, and drag the measure above into Values. Same result as DISTINCTCOUNT, but with less performance overhead (I think).
Working in Cognos Report Studio 10.2.1. I have two query items. First query item is the base table which results in some million records. Second query item is coming from a different table. I need to LEFT OUTER JOIN the first query item with other. In the third query item post the join, I am filtering on a date column which is in formatYYYYMM to give me records falling under 201406 i.e the current Month and Year. This is the common column in both the table apart from AcctNo which is used to join both the tables. The problem is, when I try to view Tabular datathe report takes forever to run. After waiting patiently for 30 mins, I just have to cancel the report. When I add the same filter criteria to the 1st query item on the date column and then view the third query item, it gives me the output. But in the long run, I have to join multiple tables with this base table and in one of the table the filter criteria needs to give output for two months. I am converting a SAS code to Cognos, In SAS code, there is no filter on the base table and even then the join query takes few seconds to run.
My question is: Is there any way to improve the performance of the query so that it runs and more importantly runs in less time? Pl note: Modelling my query in FM is not an option in this case.
I was able to get this resolved myself after many trial and errors.
What I did is created a copy of 1st Query item, and filtered 1st query item with current month and year and the for the copy of 1st query item added a filter for two months. That way I was able to run my query and get the desired results.
Though this is a rare case scenario, hope it helps someone else.
I would like to create an end report, which shows a calendar(month) with aggregation for the specified data.
I am working on cognos 8.4, I have a requirement where I have to show the statistics of the month in a calendar form. The report should be dynamic and it should display the details of the particular month.
Any help or advice is highly appreciated.
Have you tried creating a crosstab? I would create an SQL view of your data to get something like this:
select amount, DayNumber, DayofWeek, MonthName, MonthNumber, YearNumber, Weeknumber
from your_view
Within Report Studio filter on YearNumber and MonthName (ordering by Monthnumber). Then create a crosstab where columns would be DayofWeek and rows would be Weeknumber. Inside the crosstab drag the amount field.
Remember Cognos auto-sumarize everything by default unless you override that behavior.
One thing I cannot think to figure it out is how to display the DayOfMonth within the crosstab. That one is tricky since the data is string and it is not groupable in any calculation (MAX, SUM, AVG, etc). If you can find a solution for that, please let me know. Cheers.
You can use a repeater table, and the table will use a query which gives you the dates, you can apply the filter in that query for the user-selected month. After you have that part working, you can pull a list into the repeater table and then use master-detail relationship from the date query to the list query, then you can design your list inside the table.