Is there a way to apply week-over-week growth rates from prior year to current year data in Tableau? - tableau-api

I have a Dataset in Tableau with fields: Date, City, Sales. The data is for all days of 2022
I created Week - over - Week growth rates for 2022. My worksheet look like this:
Iso-Year (Date)
Iso Week (Date)
City
SUM(Sales)
2022 Growth %
2022
W01
New York
2500
0
2022
W01
Boston
400
0
2022
W01
Minnesota
1300
0
2022
W02
New York
2600
4%
2022
W02
Boston
200
-50%
2022
W02
Minnesota
1340
3.07%
2022
W03
New York
2400
-7.69%
2022
W03
Boston
800
200%
2022
W03
Minnesota
1200
-10.44%
The calculated field I used to get 2022 W-o-W growth %:
(SUM([Sales]) - LOOKUP(SUM([SALES]),-1)) / SUM([Sales])
I want to use the 2022 growth rate for a specific City and Iso-Week combination to the same City and Iso-week combination for 2023. As an example,
New York grew by 4% from W01 to W02 of 2022, so I'm looking to apply the same 4% to calculate Sales in W02 of 2023 (W01 2023 Sales * 1.04) and so on. Like this, I want to apply growth rates for those week and city combination of 2022 to calculate Sales for all future weeks of 2023. I already have my W01 2023 data to start with.
Iso-Year (Date)
Iso Week (Date)
City
SUM(Sales)*Growth
New Sales
2023
W01
New York
4000
4000
2023
W02
New York
4000*(1+4%)
4160
2023
W03
New York
4160*(1-7.69%)
3840
I cannot find a way to do this with my dataset. I cannot use FIXED function because I've used a table calculation in my calculated field for growth rate.
My struggle is that I'm using a Dataset provided to me by my organization and cannot modify the table logic. After I created the calculated field, I cannot use the 2022 growth % if I have 2023 data filtered in.
I have an option to create a custom data source but I do not think that the effort is worth for this.
Does anyone have an idea to make this possible?
I can provide more information if the description is not clear enough. Thanks a lot!

Related

Solving duplicate rows in (Stata)

I have dataset that is composed of two merged datasets. First, official unemployment figures from country statistical offices, while the other is unemployment figures from the ILO's modelled estimates.
For some countries like Jordan, it is named JOR but JOR_total in another dataset, although it is measuring the same demographic group. This results in having two rows per gender for the same year. However, I essentially want to keep one row per country and per gender.
Below is how the dataset looks like:
year gender country unemployment_official unemployment_ilo
2019 Female JOR 19
2019 Male JOR 8
2019 Female JOR_total 17.3
2019 Male JOR_total 7.4
I would like to change the dataset to look something as below:
year gender country unemployment_official unemployment_ilo
2019 Female JOR 19 17.3
2019 Male JOR 8 7.4
2019 Female EGY 17 22
2019 Male EGY 5 9.4
Solved this before merging the two datasets, with the following:
// Removing countries with duplicate entries
drop if country=="JOR"
replace country="JOR" if country=="JOR_total"
And it looks as:
year gender country unemployment_official unemployment_ilo
2019 Female JOR 19 17.3
2019 Male JOR 8 7.4
2019 Female EGY 17 22
2019 Male EGY 5 9.4

Is it best practice to include current month or only previous completed months in monthly average equation?

I am trying to calculate a rolling "monthly average" equation for personal expenses and wondering if I should include the current month before it is over or if I should only include previous, fully completed months?
For instance, in mid-September, should I include January - August OR January - September and so on?

Monthly average from daily data

I have a dataset of energy efficient smart AC units. Each one has an ID, and each unit has daily data that represents the cost saved (in dollars) for each day.
I want to create a bar graph that shows the average savings, per month, per unit. I'm really struggling, however. AVG([Elecsavingscost]) only gets me the average daily savings in a given month. SUM([Elecsavingscost]) * 30 gets me pretty close to what I want, but of course, not all months have 30 days.
Is there a more intelligent way to do this? I'm presuming it's possible...
It can be very easily done using R software. Following is the code to convert daily data to monthly data
install.packages(c("zoo","hydroTSM")
library(zoo)
library(hydroTSM)
data=read.csv("data.csv")
data #data should contain 2 or more columns; 1st column should be date in
#English (U.K.) format, 2nd and subsequent columns should be your daily data
date Elecsavingscost
01-01-1984 18.8
02-01-1984 20.2
03-01-1984 19
04-01-1984 19.6
05-01-1984 21.8
06-01-1984 21.5
.
.
.
25-12-2014 13.6
26-12-2014 13.6
27-12-2014 16.2
28-12-2014 18.2
29-12-2014 16.7
30-12-2014 19.4
31-12-2014 18.5
x1 <- zooreg(data$Elecsavingscost, start = as.Date("1984-01-01"))
## Daily to monthly conversion
Elecsavingscost_monthly<- daily2monthly(x1, FUN=sum, na.rm=TRUE)
write.csv(Elecsavingscost_monthly,"Elecsavingscost_monthly.csv")

Calculating percentage of survivors per cohort over time in Tableau

In my dataset, I have three columns of data:
CustomerID, BoxCount, MonthCreated
1001 1 Aug 2015
1001 2 Aug 2015
1001 3 Aug 2015
1002 1 Sep 2015
1002 2 Sep 2015
In the screenshot below, I have built a table that displays the count of unique CustomerIDs at each BoxCount level, by cohort (MonthCreated, which is when the customer signed up).
BoxCount level 1 is the full number of people who signed up in MonthCreated X, because everyone who has signed up receives at least 1 box. Then people start cancelling. The number of people who reached BoxCount level 2 for May 2015 (according to the screenshot), is 156,823, or 86.87% of total people who signed up in May (180,525).
I need to create a second column next to the count of customers that displays the % of customers remaining at each BoxCount level, per cohort (people who signed up in the same month).
I have tried using the Quick Table calculation Percentage of Total, with the computation method being "Table (Down)" but it only seems to work for the first month of MonthCreated. I would like for each subsequent month to have 100% for BoxCount level 1, and the following % to be a portion of the number at each month's level 1. I can't figure out why for July, the % starts at 83.89% and not 100%.
Can anyone help me figure out how to calculate this percentage and also to add it as a new column instead of replacing the column of raw counts?
Thanks!
Looks like you're almost there. Did you try changing the calculation definition by changing the values it summarizes from or the level?
Some example:
And for it to be replacing the column of raw counts, you can just add the raw counts column again in your view and you'll have both.

Cumulative Days in Overlapping Date Ranges

I use Crystal Reports 11.
What I'd like to do is get a count of the unique days a student was enrolled in one of our many programs. If a student was enrolled in 3 programs in which the dates overlapped, I'd just want to count each day once and get a number.
Example using a student:
Algebra Jan 1 to Jan 10: 10 days
Science Jan 4 to Jan 11: 8 days
English Jan 9 to Jan 13: 4 days
I'd want the answer to be 13.
Good point. If they always over lap then this will work
Create a formula that finds maximum end date and the minimum start date based on patient. Then minus each formula.
i.e.: Maximum({xxx.enddate}, {xxx.patient}) - Minimum({xxx.startdate}, {xxx.patient})
If there are gaps between program dates, this won't work because it will include them.
Grouping the field by the patient name and Using
DistinctCount()
may be helpful.