Is tableau has a opportunity to create calculated column for table? For example here are 2 column with some number and I want to make third column with formula like this
If(column1>column2;column1;column2. I see there is option to create calculated field with summarize columns but I just want to compare them.
If you only want to create a new column storing the max between 2 original column, you just need to create a calcultaed field like the following:
if column1 > column2
then column1
else column2
end
EDIT
Or even simpler
MAX([column1], [column2])
There are two (overloaded) functions named MAX(). With one argument, MAX() is an aggregate function that operates on a column of values and returns the maximum - just like other aggregate functions like SUM(), AVG() etc. With two arguments, MAX() is a record level function that operates on an individual data row and returns the larger of its two arguments. MIN() behaves similarly.
Related
Can someone explain the purpose of using bitwise operators(like BIT_OR) in MySQL queries. For example, if have a table such as following:
What is the purpose of aggregate operation like:
SELECT name FROM table GROUP BY name HAVING BIT_OR(value) = 0;
What exactly does the BIT_OR do? I understand the actual operation of converting two integers to binary and determining if each pair of corresponding digits are either 0 or 1(if at least one of them is a 1), but what happens with varchar or other non-number columns columns? I know for example, SUM aggregate function can give me the sum of a column of each group. Likewise, what does BIT_OR tell me for each group?
**NOTE:**I randomly created the above table and query - it doesn't illustrate any specific problem
This is the table that I would like to compare the values within the row groups incrementally however I would not like to compare rows amongst groups as it would come with negative values.
How do I achieve this on the same table? I am unfamiliar with subqueries
It sounds like what you need is a Calculated Field added as a third column to your table.
Instructions:
Select the drop down menu next to "Click to Add" to create a new column.
From the choices available select Caluculated Field and then Number.
The Expression Builder will open.
All you need to do from there is select the column you want to use as your primary number (in your case Number) from the Expression Categories, insert a minus sign, then select the number you want to subtract from the first number (in your case Group), again in the Expression Categories.
Name the column you created whatever you would like.
If I have a table like so:
Name Type Val
Mike A 1
John A 4
Jerry 6
(Notice that Jerry has an empty string for Type)
And I do a query like
Select sum(Val), Type from table
How does MySQL choose which Type to put in the one row result? If I wanted to return the "non blanked"
To give some context, the Type for every row in this table should actually be the same, but there used to be a bug where there are now some values that are blank. (Note that the sum should still include the blanks)
I know I can do this in two queries, and just select Type from table where Type!="" but I was curious if there was a trick to do it in that single query.
This is valid SQL in MySQL. You are aggregating all rows to one row (by using the aggregate function SUM and having no GROUP BY clause).
Any value that is neither in a GROUP BY clause nor being aggregated is a random one. The type you get is just one of those types in the table; it could even be another one when you execute the same query again.
You can use max(type) or min(type) for instance to get the value you are after.
I have one dataset Dataset1 and in that I am displaying data based on grouping. The data is like this
CityColumn CountColumn
City1 5
City2 3
The query of above datase is like this :
select count(*) as "CountColumn" from City group by CityColumn
Here in above dataset I have counted using grouping on CityColumn.
Now I have created another Dataset Dataset2 and in that The data is like this
CityColumn
City1
City2
City3
Now in dataset2 I have add one calculated field called TotalCount and used the Lookup Function the function is like this
=Lookup(CityColumn, CityColumn, CountColumn, "Dataset1")
but It gives me an error like
Lookup includes aggregate, rownumber, runningvalue, previous or lookup function. Aggregate, rownumber, runningvalue, previous or lookup function cannot be used in calculated field.
The first two values of the lookup function must refer to an identifying value in a column. In your case the City names must be in both datasets. Think of that as a primary key. The third value is the one you want to display from the second dataset. So it should look more like this:
=Lookup(Fields!CityColumn.Value, Fields!CityColumn.Value, Fields!CountColumn.Value, "Dataset1")
Make sure that Dataset1 has the column named CountColumn that you are trying to lookup. Keep in mind that this only looks up individual rows, not aggregates. If you want to work with aggregates you can do that on top of the lookup function.
EDIT:
Since Lookup functions are not allowed in calculated fields, you'll need to use it in the Value expression in your pie chart. It should look like this:
Note that the lookup function has to be in an aggregate like a sum function for it to work as a chart value.
Instead of adding it as a calculated field in the DataSet, simply add the expression into an empty column within the details rows of the report.
I'm trying to create an ssrs report. Here's the data i have:
original data
I need to grouping and numbering based on specific column but ignoring the Entire entry row, the final result should be like this.
result
What's the grouping should be on case like this so i can put the number just like in my screenshot ?
Insert a matrix , row groups for Warehouse, Column1, Column 2
and for column groups use Amount, insert amount field with aggregate function of sum.
to add in the No. row, you will need to insert a empty column between column1 and column2 and insert an expression similar to:
=RunningValue(Fields!Test_case.Value, CountDistinct,"Tablix3" )
Whereby Fields!Test_case.Value is equivelant to Column1 and Tablix3 is equivelant to your matrix.
Example of design and report outcome, just need to correct expression for the No. column: