Skip to main content

#January0 discussing

I would like your help with the following:

* 3 calculated columns in one table.

* Total Xmas sales last year, Xmas sales up to this week last year, and Xmas sales this year

*Combining all the columns, I get a wrong last year total.

 

If I comment out this week last year, I get a correct last year total.. I think the problem is with my calculated field logic

 

IF  (DATEPART('year',[Enquiry Created]) = 2016 AND DATEPART('week',[Enquiry Created]) <= DATEPART('week',today(), 'sunday')+1) THEN '2016 Now'

ELSEIF  DATEPART('year',[Enquiry Created]) = 2017 AND [Event Date] >= ⌗November 1, 2017# AND [Event Date] <= #January 31, 2018# THEN '2017 Now'

ELSEIF  [Event Date] >= #October 1, 2016# AND [Event Date] <= #January 31, 2017# THEN '2016 Total'

ELSE 'NULL'

END

 

Help with Calculated Field Logic

Thanks for your help

3 answers
0/9000

I am extracting timestamps in Unix Epoch Time format and simply converting them with a DATEADD formula however it does not take into account DST...how would one achieve that when using an Epoch time from the database extract?

 

Calculated FIeld:

DATEADD('second',[BEGINDATETIME],#January 1,1970# )

 

The existing calculated field will successfully convert the epoch time (1,398,738,922) to a human readable long date format (i.e. mm/dd/yyyy hh:mm:ss) however it does not take into account the daylight savings time offset. How could one do this in a calculated field in Tableau or is this something that needs to be handle "pre-extract"?

 

-Derek

17 answers
  1. Aug 6, 2014, 4:32 PM

    Shawn's calculation should definitely solve your need for this year. If you need something dynamic for other years, the following should accomplish this. It dynamically finds the start of Daylight Savings Time for any year for which you have data, regardless of whether or not you have data on that specific date/month. It does the same thing for the end of DST, and makes sure that your date falls within this. It also accounts for the 2AM hour for either end.

     

    I put it all in 1 calc as it's a "black box" that just works and cuts down for "clutter" for your end user. Not as fun to develop, but should allow you to just paste into any workbook and integrate into your view. All you have to do is substitute  your time field for Order Date (I'm assuming Epoch Time). If you need a workbook, let me know.

     

    IF [Order Date] >= DATEADD('hour', 2, (IF DATEPART('weekday', DATEADD('month', 2, DATETRUNC('year', [Order Date]))) = 1

    THEN DATEADD('month', 2, DATETRUNC('year', [Order Date])) + 7

    ELSE DATETRUNC('week', DATEADD('month', 2, DATETRUNC('year', [Order Date])) + 13)

    END))

    AND

    [Order Date] <= DATEADD('hour', 2, (IF DATEPART('weekday', DATEADD('month', 10, DATETRUNC('year', [Order Date]))) = 1

    THEN DATEADD('month', 10, DATETRUNC('year', [Order Date])) + 7

    ELSE DATETRUNC('week', DATEADD('month', 10, DATETRUNC('year', [Order Date])) + 6)

    END))

    THEN DATEADD('hour', 1, [Order Date])

    ELSE [Order Date]

    END

     

    It should also be noted that I would encourage handling this in your datasource, but if this is not an option, the above works well (albeit with a slight performance hit due to calculation time).

0/9000

Currently in the database that I am pulling data from, all of the dates are formatted as numbers instead of dates.  What I was told is that the number is the number of seconds from Jan 1, 1970.  Our DBA told me to use this function, unixts_to_date, to convert the number to a date.  The problem is that Tableau doesn't recognize the function.

 

Any other ideas (besides just doing the math in a calculated field) to get the number into a date?

 

Thanks

Kevin

4 answers
0/9000

Hi Tableau community,

 

I have the base code for the case statement below, but I'm not sure what the best function is to define these ranges so that it will work as required when added to the filter shelf.

 

Parameter = [DateRange]

Dimension = [Date]

 

CASE [DateRange]

 

    WHEN '12 Months' THEN

               Need logic that uses [Date] to define range 12 months prior to the current date

    WHEN '6 Months' THEN

 

    WHEN '3 Months' THEN

 

    WHEN 'Year to Date' THEN

 

END

 

Thanks for any help!

 

Kevin

6 answers
  1. Jan 29, 2014, 5:53 PM

    You can install different versions of desktop on your machine simultaneously--which is a good idea anyway, as you can test features of the newer version while continuing to use an earlier release.

     

    There is no CASE statement in this workbook, but the main calculation for choosing the date range is:

     

    IF [Date Selection]=1 AND Date <= today() and Date >= dateadd('day', -6, today()) THEN [Date]

    ELSEIF [Date Selection]=2 AND Date <= today() and Date >= dateadd('week', -4, today()) THEN [Date]

    ELSEIF [Date Selection]=3 AND Date <= today() and Date >= dateadd('month', -2, today()) THEN [Date]

    ELSEIF [Date Selection]=4 AND [Date] <= [End Date] and [Date] >= [Start Date] THEN [Date]

    END

     

    {Date Selection] is a parameter with 4 different options (1-4).  Hope this helps.

0/9000

Hi,

 

I have a worksheet in my dashboard that has multiple values being displayed in rows with weeks as the column.  I have a parameter filter that allows the user to select their date range based on the below two calculated fields.  This all works great and I have no problem with them.  What's causing the issue is one of the measure values I now need to display on the row (Retention Rate below) is calculated with data from the previous week.  This calculation works correctly but because it's going back one week it's causing the first week in the date range to not show for this one measure.  If there a way to make my date range behave differently for this one measure or is there a better way to use the value from the previous week than what I have done?  Thanks in advance for your help.

 

Selected Start Date

CASE [Select Date Range]

WHEN "All" THEN DATETRUNC('month',[Full Date])

WHEN "3 months" THEN DATEADD('month',-3,TODAY())

WHEN "6 months" THEN DATEADD('month',-6,TODAY())

WHEN "1 year" THEN DATEADD('month',-12,TODAY())

WHEN "2011" THEN DATETRUNC('month',#January 1, 2011#)

WHEN "1H 2011" THEN DATETRUNC('month',#January 1, 2011#)

WHEN "2H 2011" THEN DATETRUNC('month',⌗July 1, 2011#)

WHEN "2012" THEN DATETRUNC('month',#January 1, 2012#)

WHEN "1H 2012" THEN DATETRUNC('month',#January 1, 2012#)

WHEN "2H 2012" THEN DATETRUNC('month',⌗July 1, 2012#)

END

 

Show Dates

DATETRUNC('week',[Full Date])>=DATETRUNC('week',[Selected Start Date])

 

Retention Rate

SUM([Retained Users])/WINDOW_SUM(SUM([Unique Users]),-1,-1)

5 answers
  1. Mar 5, 2013, 2:56 PM

    I kept thinking along the lines of hiding the data I didn't want in the current view of the charts instead of filtering it and remember something similar I had done for a running sum in another chart that needed to keep adding but not display outside the date range.  The fix was to create a week filter with the formula below to use in the Show Dates and Show Dates End calculated fields so that they work the same for the comparisons as before but now they don't actually filter out the actual data.  This is working great and fixes the problem.

     

    lookup(attr([Week]),0)

0/9000

I am trying to calculate a compliance rate for patient observations performed. by unit each month. We have 4 hospital units and the expectation is that one patient observation will be performed on each shift on each unit.

 

During a 31-day month, there should be 93 observations per Unit. During a 30-day month, it would be 90, etc.

 

I created a calculated field called 'Observation Compliance' with the goal of getting a compliance rate for the month, by unit; however, it is only returning the count of observations.

 

I tried using and LOD expression (maybe it's my order of operations), or else I'm just overengineering the calculation altogether.

 

Here is the expression with the packaged workbook attached:

 

If DATE([Date of Observation])>=⌗November 1, 2023# and DATE([Date of Observation])<=⌗November 30, 2023# THEN {FIXED [Unit]: COUNT([Continuous Observation Data])/90}

ELSEIF DATE([Date of Observation])>=⌗December 1, 2023# and DATE([Date of Observation])<=⌗December 31, 2023# THEN {FIXED [Unit]: COUNT([Continuous Observation Data])/93}

ELSEIF DATE([Date of Observation])>=#January 1, 2024# and DATE([Date of Observation])<=#January 31, 2024# THEN {FIXED [Unit]: COUNT([Continuous Observation Data])/93}

ELSEIF DATE([Date of Observation])>=⌗February 1, 2024# and DATE([Date of Observation])<=⌗February 29, 2024# THEN {FIXED [Unit]: COUNT([Continuous Observation Data])/87}

END

 

Any help would be greatly appreciated.

 

Thank you,

Jason

2 answers
  1. Feb 12, 2024, 9:55 PM

    See if this works better for you:

    {FIXED [Date of Observation], [Unit], [Patient Name]: IF DATE(MIN([Date of Observation]))>=⌗November 1, 2023# and DATE(MIN([Date of Observation]))<=⌗November 30, 2023# THEN COUNT([Continuous Observation Data])/90

    ELSEIF DATE(MIN([Date of Observation]))>=⌗December 1, 2023# AND DATE(MIN([Date of Observation]))<=⌗December 31, 2023# THEN COUNT([Continuous Observation Data])/93

    ELSEIF DATE(MIN([Date of Observation]))>=#January 1, 2024# AND DATE(MIN([Date of Observation]))<=#January 31, 2024# THEN COUNT([Continuous Observation Data])/93

    ELSEIF DATE(MIN([Date of Observation]))>=⌗February 1, 2024# AND DATE(MIN([Date of Observation]))<=⌗February 29, 2024# THEN COUNT([Continuous Observation Data])/87

    END }

    See if this works better for you:{FIXED [Date of Observation], [Unit], [Patient Name]: IF DATE(MIN([Date of Observation]))>=⌗November 1, 2023# and DATE(MIN([Date of Observation]))<=⌗November 30, 2023#

     

    Best, Don

    (Please, don't forget to click Select as Best or Upvote !)

0/9000

Hello @Jim Dehner​ ,

 

I am trying to find the number of Continuing parking permits in my report - the permits issued from September 1st of the current fiscal year. We follow the Fiscal year from Sept 1st to Aug 31st.

 

I created the following formulas to create the continuing field to calculate these records, please let me know if this is correct. I see a slight difference in the count when I validate my results, so I am trying to understand where I am going wrong in the calculations.

 

1. Created Date -FY field (by setting the default properties to Fiscal year "Sept")

[Issue date]

 

2. Created Date-FY Start date field

 

IF (MONTH(TODAY()-1) >= MONTH(#September 1, 2021#)

AND 

MONTH(TODAY()-1) <= MONTH(⌗December 31, 2021#))

THEN DATE ("09/01/"+DATENAME('year', TODAY()-1))

ELSEIF

(MONTH(TODAY()-1) >=MONTH(#January 1, 2022#)

AND 

MONTH(TODAY()-1) <= MONTH(⌗August 31, 2022#))

THEN DATE ("09/01/"+DATENAME('year', DATEADD('month',-12,TODAY()-1)))

END

 

3. Created the continuing permits field

IF [Date-FY]< [Date-FY start date] THEN 0

ELSEIF [Date-FY]> (TODAY()-1)THEN 0

ELSE [TotalCount]

END

 

Attached is the workbook, please let me know if you are able to access and view the data with calculations.

 

Any help would be appreciated. Thanks!

3 answers
  1. Mar 25, 2022, 4:02 PM

    While helpful, the screenshot doesn't show us how the result is being arrived at for Continuing vs. New vs Final...we don't have the business model or background which derives that...

     

    To simplify, can you bring that particular row of data down to FY-2022 that you have highlighted in your example for FF? If I compare for same row in Tableau, which means it starts at 9/1/2021 and carries through to current month March 7, 2022, then you should have the following data for Total Count:

    While helpful, the screenshot doesn't show us how the result is being arrived at for Continuing vs. New vs Final...we don't have the business model or background which derives that...Which would mean the FY is working...which was the original concern...

    As example, if I apply the original calculation you're using for 'Continuing' with the new FY setting in place, I get the same result:

    Screen Shot 2022-03-25 at 8.56.46 AMThe same as just using Total Count...

    Screen Shot 2022-03-25 at 8.58.28 AMSo, I think need to better define what is considered Continuing, or New, etc.... OK I'm headed off to another project will look at this thread later. D

0/9000

Hello, I am having trouble with the calculation below where qty/value is an aggregation and the PI fields are just decimal values.

 

zn(IF MIN(DATE([Date]) = DATE(#January 1,2023#)) 

then [Qty/Value] * [Jan PI]

ELSEIF MIN(DATE([Date]) = DATE(⌗February 1,2023#))

then [Qty/Value] * [Feb PI ]

END

 

I'm expecting to see the value but the above flow just returns results of 0 for all rows, any advice would be appreciated.

 

Thank you

3 answers
  1. Aug 10, 2023, 2:46 PM

    @Mason Hughes​ 

    Hi, in this case I would use something like:

    SUM(IF DATE([Date])=#2023-01-01# THEN [Qty]*[Jan PI]

    ELSEIF DATE([Date])=#2023-02-01# THEN [Qty]*[Feb PI]

    ELSE 0

    END)/

    SUM(IF DATE([Date])=#2023-01-01# THEN [Value]

    ELSEIF DATE([Date])=#2023-02-01# THEN [Value]

    ELSE 0

    END)

    If this post resolves the question, would you be so kind to "Select as Best"?. This will help other users find the same answer/resolution and help community keep track of answered questions. Thank you.

     

    Regards,

     

    Diego Martinez

    Tableau Visionary and Forums Ambassador

0/9000

@Chris McClellan​ 

 

Hello Chris,

 

I am trying to find the number of Continuing parking permits in my report - the permits issued from September 1st of the current fiscal year. We follow the Fiscal year from Sept 1st to Aug 31st.

 

Any help would be appreciated.

16 answers
0/9000

Hi,

I've just started toying with Tableau and I must be doing something fundamentally wrong on my read. My Excel data set has a column for the year, but after I read it in and convert the variable to 'Date' and then view the data, Tableau is converting all of my dates to days in June 1905. Any advice?

 

Thanks,

Jon

11 answers
0/9000