How to calculate multiple columns in one Hoc view? - jasperserver

I am using TIBCO Jaspersoft : Ad Hoc Editor to create a Hoc view, where I have to calculate some column and generate reports.
I have data source where I have two data sets.
I have MasterId,MasterName
I have multiple record corresponding to MasterId. Ex. ActivityId,Name,Type,StartTime,EndTime,MasterId (FK from MasterTable.MasterId)
I have to calculate a column 1stActivity-Delay-hours, where I have to show the difference between 2 dates in HH:MM format (12:39)
for that I have used create calculated field option and place the formula
ElapsedMinutes("EndTime", "StartTime")/60
and to filter the data I have created new measure too and place the formula like-
tblActivity.StartTime < 12-12-2017 1:10 and tblActivity.EndTime > 11-12-2017 2:20
its working fine and showing the correct output except the HH:MM format. For example its showing 24.65 and instead 24.35 or something like that. I try to use % (mod) to get the minutes but % works as percentage here So I am not able to use the MOD functionality here (1st issue)
But when I need my second column in the same view with different condition (filter) for example: tblActivity.StartTime > 12-12-2017 1:10 and tblActivity.EndTime < 11-12-2017 2:20
and Activity.Name='act1' it will mess up with 1st column calculation.
As per my understanding we can only have one data-source per view, and we can't merge multiple view with different data-source.
can anybody suggest me how can I achieve this? how can I add multiple data-source in single view.
I can do this calculation in SQL easily by using temp table(#table). For instance I will calculate the 1stActivityDelay column and store the delay-hours in temp table and then calculate the 2ndActivity delay hours with different where condition and again store it in the temp table and at the end I will select the rows from temp table. But in this tool I am not able to find any way to do this.

Related

Spotfire - Filtering a Table by Values in a Calculated Column

I am trying to filter a table visualization of all of my data by looking to see if a Study Number contains Activity A. If a Study Number contains Activity A then I want to filter for all rows containing those Study Numbers even if the Activity is not A. See mock data below. In my real data set I have ~55,000 rows.
I have created a calculated to return Study Numbers if Activity= A but I am not sure where to go from there. Thanks for any help.
If(UniqueConcatenate([Activity]) OVER ([Study Number])~="A","Y","N")
Will give you this resulting column that you can then filter on (or you can use the formula as a Data Limiting Expression:

Creating calculated columns based on where

I am trying to create calculated fields for a workflow that I will export to an excel pivot table. I am doing this by creating a view and selecting columns from another table while creating extra necessary columns.
I am faced with the task of populating rows within a column based on a calculation only when rows of another column equal a certain value. I have tried different variations of the below formula to no avail.
CREAT MATERIALIZED VIEW adwords_calculated AS
SELECT SUM("Impressions" * 1 ) WHERE AD Relevance =
"Positive Ad Relevance" AS Positive Ad Impressions
Please let me know if anything within this formula is unclear.

Tableau creating a calculated percentage (non-aggregate) based on an aggregated total

Either I am the first person to ever need to display percentages in Tableau or I do not know what to search for! I highly suspect it is the latter...
I believe what I am attempting to ask is how to make a calculated non-aggregated field by dividing by an aggregated number. Although I would prefer just to be able to display the percentages instead of a whole number.
This is how I would do it in Excel:
The data that already exists is Column A and B. In Tableau these would be non-aggregated. What I need to do in Tableau is to generate what is column C (also non-aggregated) because it does not exist in my data. In excel, all I did to get the aggregate number (total) of column B was:
sum(B1:B4)
And for the column C:
=B1/$B$5
But I can't seem to do this at all in Tableau. When I try to use the same syntax, I get an error message: "Cannot mix aggregate and non-aggregate arguments with this function."
Instead of having a calculated field, you can use a Quick Table Calculation on the column.
Right-click the pill of your data > Quick Table Calculation > Percent of Total. This will show the percentages instead. If you want to keep both, just duplicate column b first and then add the table calculation to the new column.

Tableau table filter for one column only in table

I have a really basic question that I can't figure out. I need to create a table that has multiple calculated fields, but I need only one of the calculated fields to be filtered for a specific dimension value. For example, I have the following data set (dummy data) and I want to create a table that will include total clicks for both companies, but [cost per click] from one company only, company B.
DATA SET
Company| Clicks| $ Cost
------------------------
Comp A | 100 | $20
Comp B | 200 | $40
WHAT I'M LOOKING FOR
CLICKS | COST/CLICK
TOTAL 300 | $0.13
$0.13 comes from 40/300; $40 from company B and 300 clicks from both company A and B.
How do you create a table that has multiple calculations but with one of those calculations filtered on one dimension value only?
One simple calculated field:
sum(if [Company] = 'B' then [Cost] end )/sum([Click])
This should get you in the right direction.
Based on your question and your comment, you want to divide the cost by the TOTAL number of clicks in your dataset.
Create a calculated field called "TotalClicks" and enter this formula
window_sum(sum([Clicks])) // This formula will sum the clicks field for all rows
Create a calculated field called Cost / Clicks and enter this formula
sum([Cost]) / [TotalClicks]
Add the Cost / Clicks field to the sheet and it should look like this
NOTE: If you need to partition / group your report, you may have to play around with this some. I don't use window functions within tableau very often since I usually handle the aggregation at the datasource level instead.
NOTE: Since you mentioned filtering, I will add this statement -- If you filter out any of your data, that data will not (cannot) be included in any calculated fields (To the best of my knowledge and experience, anyway). If you need to include that data (total clicks), I think the only option is to add that aggregated total to your dataset - otherwise, tableau can't calculate it if you are filtering it out.
Edit2: If you cannot change the underlying dataset, you could accomplish this by creating another datasource and joining it to your inital data source --
Data > Add Datasource, add the datasource again and change the name so you can identify it
Click Data > Edit Relationships. Click Custom and REMOVE any linked fields -- this will essentially produce a Cartesian join (every record in your first DataSource will have every reocrd from your second Datasource)
Select the second datasource and create a calculated field (ClicksTotal_DS2) using the same window_sum function
Select the first datasource and create a calculated field (named Cost / Clicks_DS2) using this formula
sum([Cost])/ [Sheet1 (test) (2)].[ClicksTotal_DS2]
Now you can apply a filter to your first data source, and your second data source will still calculate the total.

Tableau table hides categories with no data - how to prevent?

I have Tableau report where I am showing data by category in columns.
The table shows all columns when there is no filter on data. But when filter is applied, some of the categories do not have data, so table shrinks, hiding columns without data
Is there a way to always show columns regardless of data or not in that column?
Please see screenshots below.
Go to Analysis >Table layout> Show columns with no data or
Analysis>Table layout>Show rows with no data
The next step depends on whether your "disappearing" fields are dimensions or measures.
If you want to force the display of members for specific dimensions, then one (kind of complex) solution is to use an advanced Tableau feature called data blending to force the existence of dimension members, even if there are no related measure values. The trick is to make a simple data source, say a text file, that lists the members of each dimension. Use that source as the primary data source, and make the original data source the secondary source.
Go to Analysis >Table layout> Show columns with no data or Analysis>Table layout>Show rows with no data
Also You can right click on header and select show missing values if you are using line chart.
Solution 1: (When you’re working with Dates or Numeric bins)
Right click on the numerical or Date column to extrapolate the missing values. As you notice in the lower part of the screenshot, this will not work on Categorical data !
Solution 2: Categorical Data
As indicated in the accepted answer, Analysis > Table Layout > Show Empty Rows will get you the same result for Categorical (Text) Data
Solution 3: Calculated Columns
If for some reason, none of the 2 above point & click solutions work, you can create calculated columns to calculate the measure for each of the Categories with the below formula and then line them up on the Columns to achieve the same result
Profit (Category 1)
IF MyColumn = "Category 1" THEN
Profit
ELSE
NULL
END
Profit (Category 2)
IF MyColumn = "Category 2" THEN
Profit
ELSE
NULL
END
Not the most convenient solution when you have hundreds of unique values in your column, but nevertheless a workaround !