Add filter/parameter in calculated field tableau - tableau-api

I'm trying to create calculated field in tableau, my below query is showing valid, however I want to give filter or parameter to it. For ex: I have a field called Account number and I want my below query to show sum of all the quarters revenue on account number level.
Sum(If ([Qtr]='2019-Q1' OR [Qtr]='2019-Q2' OR [Qtr]='2019-Q3' OR [Qtr]='2019-Q4')
THEN FLOAT([Revenue]) END)

Your logic will work.
For parameter: Create a parameter with String data type, add all field names to it. Then create a calculated field based on the parameter list. Add that calculated field to row shelf then change Parameter, the above formula will be recalculated.
For Filter: You can add filter directly.

1st option:
Add Account number as row in your worksheet
Create a Parameter String with values: 2019-Q1, 2019-Q2, 2019-Q3, 2019-Q4
Update your calculated field to:
If [Qtr]='Parameter Value' THEN FLOAT([Revenue]) END
Add this field as text and the value of sum will be for only that Qtr period
2nd option:
Add Account number as row in your worksheet
Create a Parameter String with values: 2019-Q1, 2019-Q2, 2019-Q3, 2019-Q4
Update your calculated field to:
[Qtr]='Parameter Value'
Add this field to the filters and the whole worksheet will filter on that Qtr period
You can also add another parameter for the year to be more flexible on the years

Related

Is there a way of creating a Serial Number based on other inputs on a MS access form?

I have some samples I need to take.
In order to create a good identifier/serial number for the samples, I want it to be a product of its characteristics.
For example, if the sample was taken from India and the temperature was 40 degrees then I would click dropdowns in the form to create those two entries and then a serial number would be spat out in the form "Ind40".
Assuming that your form is bound to a table, you can create a calculated column in the table that concatenates the values from other columns into a single value.
For instance, create a new column and give it a name (for example, SerialNbr). Then for Data Type select "Calculated". An expression builder window will appear:
Enter the columns you'd like to concatenate and separate them with &. Here is an example of how the expression could look:
Left([Country],3) & [Temperature]
This expression takes the first 3 chars from the Country column and combines it with the value from Temperature column to create the value in column SerialNbr. The calculated column will automatically update when values are entered into the other fields. I'd also suggest adding another value to the calculated expression to help avoid duplicates, such as date/time of submission.

Filtering Based on a Different Column on Tableau

I'm wondering if something like this is possible.
Assume I have a data table like this:
I want a filter, where user picks France for example, but the data is filtered based on corresponding Continent value, e.g., all Europe records should show up.
Is this possible?
Sure, We can do that. If you add country to Filters shelf, Tableau will show only records of selected value. In our case, if we filter "France", Tableau shows only records which has France. So we will miss other Europe records. Parameter can handle this scenario. Follow below steps.
1.Create a String parameter
2. Create a calculated field
3. Add the created calculated field to Filters shelf then choose 'show'
4. Right click parameter then 'Show parameter control'. So it will works like filter
Method 2: Dynamically change parameter value
Pros: No hard coding, dynamically changes value based on selection. It works, well on dashboard
Cons: You will not have drop down for selection like filter. So, you need to click a chart to trigger the changes.
1. Create a String parameter with allowable values as 'ALL'
2.Create a calculated field
3.Create a parameter action in dashboard.
Dashboard-> Actions-> Add Action -> Change Parameter
In Change Parameter dialogue box, set target parameter as 'Parameter Name' and value field as 'Continent'
4. Add the calculated field to filter and select 'True' on other sheets
5. Final Dashboard looks like
Click the icon on the selector sheet. It will automatically filter data on data sheet.
Inside the selector sheet

Tableau - Filter/Parameter For Different Date Ranges

I am trying to set up a filter or parameter for different date ranges in Tableau, such as:
Previous Week
Previous 4-Weeks
Previous 8-Weeks
based on the most recent data in the database. Is this possible?
Edit:
I should have been more clear here.
Is it possible to only have these options in the filter and have it based on the maximum date in the database?
Update
Based on your comment and updated question, you can do it as you intend, though it isn't as straight-forward.
NOTE: I did this very quickly and with a random data set, so it will be important for you to test this thoroughly with your data set.
Steps:
Create a parameter control that the users will use to change the selected date range. I created this as a list of strings with values that I can use directly in a calculated (after simple casting):
Create a calculated field that you will use as a filter that references the selection of the parameter control. It tests to see if the difference (in weeks) between the maximum date in the view and the date of any given row is less than the value of the parameter.
Calculation: INT([Date Filter Parameter]) > DATEDIFF("week",ATTR([Date Field]),WINDOW_MAX(MAX([Date Field])))
Place the calculated field in the filter box and set it to True.
You will be able to filter your data like so:
Original Answer
Yup - that is built into Tableau.
Add your date to the filter and select the "Relative Date" option:
You can set the defaults - users can change these later:
Then just "Show Filter":

ssrs sum function in textbox

I have 2 datasets in my report. And I need to put a number of rows that meet a certain condition in a text box.
Here's what I have so far:
=Sum(IIF((Fields!OPEN_TIME.Value, "calls")=Parameters!Date.Value,1,0))
I get following error while running the report:
The Value expression for the text bix uses an aggregate expression without a scope. A scope is required for all aggregate used outside of a data region unless the report contains exactly one dataset
What do I miss?
Here if you are specifying a dataset name to a field like this "(Fields!OPEN_TIME.Value,"calls")" its a syntax error.. if you are using the field in a table which is assigned to dataset1 and table is assigned to dataset2 or field in a text box, then the field should be used with aggregate or "First", "Last"
Example:
first(Fields!OPEN_TIME.Value, "calls")
last(Fields!OPEN_TIME.Value, "calls")
sum(Fields!OPEN_TIME.Value, "calls")
Count(Fields!OPEN_TIME.Value, "calls") ...etc
In above scenario rather than taking a textbox, take a table with single cell assign the dataset "calls" to it then go for below expression:
=Sum(IIf(Fields!OPEN_TIME.Value = Parameters!Date.Value, 1,0))

Crosstab Sorting in JasperReports

I have a column group in a Crosstab that is a String.
It uses the field SectionName.
There is another field, SectionID (Integer), that I want to sort by.
I put $F{SectionID} in the Sort By Expression but I get the error:
1. Field not found : SectionID
This field is in the dataset. I can add a group on this field and display it. When I try to use it in sorting I get the error.
Is it possible to display one field in the column group header but sort by another?
Thank you
Yes you need to create another row group for you SectionID and make sure it is first -tweak in the XML - and then remove the text box from the visual display