Pivot table with each column having the previous columns value deducted from it - qliksense

I have a pivot table with a dimension of 'companyname', column of 'month' and a measure of SUM(number_of_sales).
I want to change the measure expression so each column shows the number of sales minus the number of sales in the previous month, so sort if the opposite of a cumulative, the idea being to show how the number of sales per month has increased month on month.
How would i go about this, i'm not even sure where to begin?
Was thinking maybe something like
SUM(IF(column=column(1),number_of_sales,IF(Column()=column(2),
But im having no luck.
Is anyone able to point me in the right direction?
Thanks!

Try to use Above function:
SUM(number_of_sales) - (Above(Sum(number_of_sales),1,1)).

Related

Power BI - Calculating a price/cost until a variable end date

Let's say I have a table of projects/programs/subscriptions/etc, it doesn't really matter as long as there is a price or cost per some amount of time. My table includes at least the following columns:
[ProjectName]
[StartDate]
[EndDate]
[CostPerDay]
I'm trying to allow the user to choose another date (slicer I assume?) and display the cost of each and all projects up to that date. Is this possible?
Edit: After the first responses I realize the original question was very poorly worded. Sorry about that. I've reworded it and I'll explain more here:
I am not trying to filter the programs by end date. I'm trying to sum a cost up until the end date OR slicer date, whichever is earlier.
Here's a short example table:
So we can also think of it as a Gantt chart like this:
Now imagine sliding a vertical line along that chart. I want to see the total cost up to that date.
I'm sure it will have to do with counting days between start date and the slicer date, then multiplying by cost. But how do we not include days after the end date of each project? Or it may be easier to do a range slicer with a min and max date, but again not counting days before or after each project.
To word it differently: can I input a date range, count the days that each project has in common with that range, and (the simple part) multiply days by cost?
It looks like what you need is a table visualization with a slicer for End date. Once the table and slicer are created, you can click on the small down facing arrow in the slicer and choose "Before". If you want both start date and end date in the equation, then you would have to add one more slicer for "Start date". If this is not what you are looking for kindly provide additional details so that we can help you out.

Aggregating data from the US stock market in Tableau, using different time frames

I am a very basic user of tableau and I have not found an answer to my question.
I have a txt file that has historical daily data for 98% of all the stocks in the US, with their daily capitalization. Each stocks has its TICKER, Daily Market Value for every trading day of the year, and its SECTOR.
I did a simple time series that display SUM([Mktval]) (sum of all individual market values) across all stocks, on a daily daily, and where I can see that the total value as of 2016 is about 24 Trillion USD, as in the image below.
When I change the view column from DAY to YEAR, I don't see the right values, but something a lot larger. So I realized that I need to do SUM([Mktval])/252 to get the right value for a year (there are 252 trading days in a year).
If I change the view to MONTH, as in the chart below, the numbers are again wrong because 252 is not the right value to use in the division.
Is there any way that Tableau can adjust the values automatically to reflect the AVG MktVal across different time intervals?
Thanks
Replace SUM(Mktval) on the Rows shelf with the following calculated field
avg({ fixed day(Date1) : sum(Mktval) })
That solution is all in one step. It is perhaps a bit more clear to use 2 steps. First, create a calculated field called total_daily_market_value defined as
{ fixed day(Date1) : sum(Mktval) }
Then make sure that calculated field is a measure. It is an LOD calculation that you can think of as a separate table with one value for each day showing the total market value for that day.
Drag that measure to a shelf, and then change the aggregation function to AVG(), MEDIAN(), MIN(), MAX() or STDEV() as desired. Tableau will aggregate the total_daily_market_value using your chosen aggregation function for whatever values of Date1 are in your view.

Tableau : How to get the Dashboard always display the latest 10 days worth of group statistics

My input text source always contains last 12 months worth of data. e.g: Current month is October. So My input source contains data starting from last Oct 1st to till date. But I want the aggregate statistics to be displayed on a daily basis for last 10 days of sales , 30 days of sales, 45 days of sale per product across various regions
I am trying to use window_avg fuction with something like window_avg(sum(sales), first() + datediff('day', window_min(min([date]))-1, dateadd('month',1,window_min(min([Date]))-1)) * 13,13) something like that. But I am not able to crack the exact logic.
Could you please suggest me some better way to achieve this, rather than using these kind of calculations. Also I am afraid if this goes wrong if there is data missing in the middle one or two days.
Any help is appreciated.
A very simple thing is to use a relative date filter. There's a UI for you to select they last N days.
Put the date on the columns shelf and set it to the date truncation of year-month-days. Put your measure row shelf. Put the date pill on the filter shelf too and use a relative date filter.
If you are doing simple aggregate like the sum of sales for a day it's easy and you'll not need to do anything else. You can can also fairly easily create a table calculation by right clicking on the measure and choosing one of the quick table calculations. Even when I'm doing a more sophisticated calculation, I start with a quick table calculation and then start editing.
If you are doing something like a moving average, the filter and the moving average can interact. For example, if I'm showing a 5 day trailing moving average over 30 day period, the first few days do not get averaged in the same way -- you don't have days over 30 days ago. If that's not really an issue for you, that's cool and you are done.
If it is an issue, it's going to be trickier. I'd suggest creating a second filter based on a table calc. The reason is the order of operations in Tableau. The raw data is filtered then aggregated by the database, then the table calcs are performed. If there are any filters on table calculations, then they are filtered after that. So basically, in my example, you want create a filter for 35 days on the date, then create a table calc on the date -- like using the INDEX() function. Filter the index function to show 30 days worth, then you've got a moving average that uses 35 days to compute the average, but only shows 30.

Tableau Draw Financial Data Series

I am new to tableau. I am just trying the simplest task: I want to draw a stock price time trend. I have data and I have price. But no matter how I tried, tableau seems no option for this raw data drawing-- you have to select a measure, whether sum or average or count but no option for just raw data. Can someone tell me how to do this? Thx!
Sum should be fine and as you add dimensions the granularity will be determined. For example, Take one of your stocks and add the date to columns and the symbol to rows. Most likely you want to see daily close price so right click and change to exact date. At this point the sum shouldn't matter because you should only have one price for each day in your record. If you have hourly price data, I would suggest using close price or change the date to the hour level.
In the Analysis menu uncheck aggregate measures, then no aggregations are performed on the measures and you see all the values.

calculating percentage of average in tsql

I have a set of records associated with IDs. there may be any number of records in this association, with currency values. one of these values is flagged as selected. I need to calculate an average of all the associated currency values, then take a percentage between this average and the lowest value, grouped by ID. all the data needed is in one table:
input:
table x: ID, Selected, DollarAmt
output:
view y: ID, Average, Percentage
I'm having problems creating this query(view) and it's driving me nuts. can anyone at least point me in the right direction?
Thanks all.
You can use this query:
select Id,
AVG(DollarAmt) Average,
AVG(DollarAmt)/MIN(DollarAmt) Percentage
from TableX
group by Id
But i´still don´t understand the need of the "Selected" variable in TableX
Regards