Tableau calculated field that refers to its own previous lagged (-1) value to calculate - tableau-api

I need help on a basic calculation that I'm unable to figure on Tableau.
I am trying to setup a calculated field that has dependency on its previous value to calculate its current value. Here is a simple example from Excel -
Sample Exhibit
As you can see, each value in a row is dependent on its previous value and multiplied by a constant.
In Tableau, when I'm trying to create a calculated field, it is not letting me refer to itself (-1 lagged value) in the code. I'd appreciate any help on how this can be resolved. Thanks in advance!

Tableau can do this client side with a table calc. You’ll have to learn how table calcs operate from the help- especially partitioning and addressing. Then you can use the function Previous_Value() to refer to the previous value. Practice on something simple first to make sure you understand how previous value() works. Hint, the argument to that function doesn’t mean what most people assume it means
If you want to perform this calculation server side instead, then you’ll need to use custom SQL so you can specify an analytic aka windowing query

Check the LOOKUP field to get the value from the preceding row. For example: LOOKUP(SUM([Value]),-1)
https://help.tableau.com/current/pro/desktop/en-us/functions_functions_tablecalculation.htm#lookupexpression-offset
You may need to make yourself familiar with the Table Calculation partitioning if not getting the expected result.

Related

MS Access use DATE() in a calculated field

I am using Microsoft Access 2016. I am trying to find out how many years exist from the current year until a future year. I have a column that is end_date. I am trying to create a calculated field that is essentially YEAR(end_date) - YEAR(current_year). I tried to use YEAR(DATE()) but DATE() is not allowed to be used in a calculated field apparently.
Is there no way to do a calculation like this?
Nope. Calculated fields are cached and static, so are NEVER allowed to contain ANY information that will change over time, due to system settings, or anything else that is not directly entered in that row.
However, you should not be using calculated fields anyway. See http://allenbrowne.com/casu-14.html, among many posts advocating for not using calculated fields.
Instead, use queries to do calculations. That way, you won't have any trouble using the current date, and won't have to deal with the possible errors and portability issues calculated fields come with.
I changed my thinking to calculate this in a form. It does not seem good practice to have a field in a DB that changes everyday.
In a form, you can use this expression as controlsource for a textbox:
=DateDiff("yyyy",Date(),[EndDate])
However, that return the difference in calendar years. To find the count of full years, use a function like AgeSimple and this expression:
=AgeSimple([EndDate])

Microstrategy - AddDays

I need to be able to use the AddDays function to derive the last week from the date column that I have in the dataset.
So, I have delivery_date of 3/21/2018, then I want to derive AddDays('3/21/2018',-7.0) - only that I want to do do this for every row in the dataset. But, the AddDays function only takes a metric. Can you suggest how I can work around this situation?
Thank you in advance,
Abhilash
As usual it depends on what you want to achieve.
If you need an attribute that returns delivery_date - 7, just create a new attribute and in the definition of the expression you can put a formula like [delivery_date] - 7 or use a pass-through function like ApplySimple to write the formula for your database (more info here).
Note: If you do this, you need to do the form expression with the formula (or the ApplySimple) only for the forms mapped on the fact table, the forms mapped on the lookup table (your Day dimension table) should be without formula, otherwise parent level will returns wrong values. Also if you don't a lookup for this new attribute create an alias or enable -Attribute Role Recognization more here.
If you need to calculate metric values for delivery_date - 7, then in that case you need to use a transformation metric. You will need to create a minus 7 days or same day previous week transformation, then associate it to the Delivery Date attribute and create the needed metrics. The last week transformation is included in the MicroStrategy Tutorial project.

Range values in Tableau

I want to visualise the below excel table in Tableau.
When adding this table to Tableau it shows Salary values as String and thus under Dimension Tab and not under Measure, thus cannot make proper graph from it.
How to convert this Salary range values to Int ?
As #Alexandru Porumb suggested, the best solution is to have a min_salary column and a max_salary column — unless you really have the actual salary available which is even better.
If you don’t want to revise the incoming data, you can get the same effect using the Split() function in a calculated field from Tableau to derive two integer fields from the original string field.
For example, you could define a calculated field called min_salary as INT(SPLIT([Salary], ‘-‘, 1)). Split() extracts part of a string based on a separator string. Int() converts the string to an integer.
You could simplify the way it sees the data and separate the salary column into Min and Max, thus you wouldn't have the hyphen that makes Tableau consider the entry as a string.
Simplistic idea, I know but it may help until a better solution will be provided.
Hope it helps

Is it possible to sum the expression column in SSRS

I am stuck in a scenario where client needed to do sum of column which is containing calculated values(Expressions) which are calculated at the run-time (At the time of generating report).
I suggested client to calculate this column at database side and return this column to SSRS dataset but due to some circumstances it is not possible.
Any help on this will be greatly appreciated.
Thank You
I don't have comment access So Iam not able to ask you more details. You can SUM up the calculated expression in SSRS AS you didn't mention how it looks.I am getting one example.
If this is how your normal cell of calculation looks,
=Fields!FirstCol.Value+Fields!SecondCol.Value
Then the SUM can be
=SUM(Fields!FirstCol.Value)+SUM(Fields!SecondCol.Value)
And if you added the calulatedColumn in the Dataset itself then it becomes more simple as you just have to do as,
=SUM(Fields!CalculatedCol.Value)

add extra column value to a column sum

I have the following issue: I have a report that uses a Dataset as its datasource. The dataset has two tables, one would be the main table, say Employee, and the second table is EmployeePaycheck, so an employee can have several paychecks. I can compute the sum of a column in the second table, say paycheckValue, but what I can't seem to do is also add to this computed field the value of some additional fields in the Employee table, such as ChristmasBonus or YearlyBonus, to see how much the employee was paid at the end of the year.
Without knowing more information on this it will be difficult to answer, but I'll give you a couple things to look for.
First, I would make sure that the fields are of a similar type that will allow for a summary. For example, if one is a string then a summary wouldn't be able to be done without casting or convertingthe value to a number. I'm assuming that the fields are probably number or decimal columns so that is probably not the case.
I'd also check to make sure that none of the values that you are trying to sum are null. I haven't tested this, but I believe that it will not sum correctly if one of the rows has a null value. In this scenario you should just be able to use a formula field to check for the null and if the field is null return 0 instead. Then you can use the formula field in your calculations instead of the field itself.
If neither of these are the case please provide a little more info how you are computing the fields and what is happening when you do it.
Hope this helps.