How to Calculate YTD (Jan to prev month) in a single column in tableau - tableau-api

Original post - https://community.tableau.com/thread/206909
I have a report in which I have sales per month in the column and commodities in the row. The data show actual sales and future estimates for each month.
Need to calculate Year-To-Date (YTD) total for 2016 (from Jan to Previous month) and have it in a single column at the end of the actual values.
I already created a calculated field - YTD
IF
YEAR([DATE]) = YEAR(NOW())
AND
MONTH([DATE])< MONTH(NOW())
THEN
[VALUE/UNIT]
ELSE
0
END
But when I add to the view, it creates a another section for YTD with sum for each month till April.
Can someone please help me in how to achieve this in Tableau?

There are couple of ways to achieve this view in Tableau
1. To create calculated field for each Month and YTD and add measure names in Row & Measure values in Text
2. Make union of 2 queries - one that select all the correct values & second that have YTD calculation in month column. Then use pivot it

Related

How can I show cumulative percentage or sum of an attribute in a line chart power bi

I have a business requirement to show the trend of cumulative percentage of an atribute over last 2 years. I used a measure to create running total of the attribute for this year and the results are correct.However When I tried to apply the same logic for the past 2 years it is giving me incorrect values.I have created a date table that spans from 2021 to 2023 dec and The X axis of the chart displays weeknumber.Could some one help me with this issue?
Thanks in Advance!
The measure for this year :
Cumulative2023 =
CALCULATE(
DIVIDE(
'Table'[CY CountNum2023]
,'Table'[CY CountDen2023]
,0),
FILTER(
ALLSELECTED('Table'),
'Table'[CreatedDate] <= MAX('Table'[CreatedDate])
)
)

Cumulative Values on Missing Data Quicksight

I'm trying to create a cumulative quarterly count divided by week. I have the underlying table that looks like this:
Date
Id
01/01/2022
X
02/01/2022
Y
The result is this
Screenshot of the problem](https://i.stack.imgur.com/9tmFA.png)
There are some white spaces due to particular weeks where there are no data. I would like to fill these blank spaces with the value of the week before (as it should be on a cumulative count) and with zero if it's the first week of the quarter.
Is there a way to solve this problem without creating any support table or any "fake data" to avoid the cell to be blank?

Looking for YOY YTD formula that works with fiscal years in tableau

I am looking for YOY YTD formula that works with fiscal years in tableau.
Method 1 appears to work here: https://resources.useready.com/blog/ytd-cy-vs-py-in-tableau-2-methods/ but does not work for Fiscal years.
the current year filter starts at Jan.
Is there anyway to adjust method 1 to work with fiscal years?
Note: i tried default properties-> fiscal year start to July and that did not work
See "goal in tableau screenshot below"
You're almost there, assuming you computed what you're showing in Tableau
and didn't just mock it up in Excel.
If you don't have one, create a calculated field "FY-Number" where
January -> 1, Feb -> 2, etc. You're already sorting in that order
so maybe you already have such a field.
Assuming your "average" is a "total" ( using AVERAGE ),
all you need now is a filter to select FY-Number < 7.
Which you COULD do manually.
But if you want this to be automatic, and always total down to the most recent month, you could do the following. There may be better ways but this works.
And I have a hierarchy of FY-number and Fiscal-Month-number for generating the grid.
Compute a running number which we can maximize, a sequential number crossing all years, for the month. I used formula for FMRun to be
[FY num]*12 + [FM num]
which has a max of 270 for December 2021. Tableau can find the max.
Next, invert that, basically, to find the max month number.
FMInvert formula:
{FIXED :(MAX([FMRun])/12 - FLOOR(max([FMRun])/12))*12}
which has a value of 6 for the data given.
Finally, filter on that with this filter I called whatmax, which we want true:
if [FM num] <= [FMinvert] then TRUE
else FALSE
END
And voila, you're done.
Here's the workbook.
https://public.tableau.com/app/profile/wade.schuette/viz/YOY-YTD-answer/Dashboard1?publish=yes

Compute average (with condition) in Tableau

Wanted Result: Average of the turnover value on days that are between the start and end reference period.
Using Tableau Desktop
Lod expression
The first step is i return the turnover value on days that are between the start and end reference period, and return null otherwise.
Daily Turnover in reference period
IF [Date]>= [Start reference date]
and [Date]<= [End reference date]
THEN [Amount] END
Second Step is to calculate the average across this range of values for each product.
Average Turnover in reference period
{FIXED [Product]: AVG(Daily Turnover in reference period)}
Here a screen shot
The average must be 2331 and not 24.
Really i need HELP.
Thanks.
There are multiple possible approaches, here is one.
Define an LOD calc as Daily_Amount_Per_Product
{ FIXED Product, Date : SUM([Amount]) }
Put Date on the filter shelf and select the range of dates you want to analyze. Put Product on the Rows shelf and put Daily_Amount_Per_Product on the Columns shelf.
At this point you are almost, but not quite done. Since your LOD calc as at a deeper level of detail (has more dimensions in play) than your view, Tableau will perform aggregation to get a result at the same level as your view - which is why you see the word SUM before your field on the Columns shelf. If you want to see the average instead of the sum, change SUM to AVG and you should have your result.

Execute IF-THEN_ELSE before Execute Calculation - Tableau

I have a graph below.
I would like to calculate lapsed rate which is sum of lapsed value divided by sum of inforce value. I use the formula below in calculated field.
abs(sum(if[Status]='lapsed'then[TotalAmount]end))/abs(sum(if[Status]='inforce'then[TotalAmount]end))
However that formula will also pick the value from Q2 (quarter 2) 2016. What I want to do is to tell tableau to check first if any quarter does not contain both inforce value and lapsed value then skip that quarter. In this case I need to calculate lapsed rate which does not include Q2 2016. How do i do this?
I'm using Tableau v.10.
Thanks.
This is just a quick approach and may not be the most efficient but it seems to work.
You need to use a combination of a row level calculation and a level of detail calculation.
The level of detail calculation can be used to flag the quarters which have both a lapsed and inforced status. Once these quarters are flagged you can calculate the lapsed rate at a row level which can then be rolled up using a sum.
Create a calculated field as follows:
Let me know if you have any questions or need any tweaks.
if
avg(
// Calculate the number of Inforce/Lapsed occurences per Quarter
IF
[Status] = 'Inforce'
or
[Status] = 'Lapsed'
then
{ FIXED
DATEPART('quarter', [Date]):
countd([Status])
}
else
0
end)
//
= 2
then
// Calculate the Lapsed Rate as both statuses exist in the quarter
sum((if
[Status] = 'Lapsed'
then [Total Amount]
END))
/
sum([Total Amount])
END