2 Replies Latest reply on Jan 22, 2019 9:10 AM by Darren Gage

    Date Calc Query

    Darren Gage

      Hi

       

      Being new to Tableau I've received previous help from this forum and have been able to create a calculated field that applies different date calcs to a row of data based on the type of record it is (working function shown below):

       

      IF ATTR([Source1].[Type])="X"

           THEN

                (DATEADD('year', ATTR([Source1].[Months]/12), ATTR([Source2].[Go_Date])))

           ELSE

                (DATEADD('day', ATTR([Source1].[Months]/12*365), ATTR([Source2].[Go_Date])))

      END

       

      What I need to do now to complete the function is set the date of the first calculation to the year end for the date that has been calculated.  I thought I could just extract the year and then build the new date with a defined day and month as shown below but this results in an error.

       

      As above code, replacing the first calculation:

      ...

      THEN

           MAKEDATE(YEAR((DATEADD('year', ATTR([Source1].[Months]/12), ATTR([Source2].[Go_Date])))),12,31)

      ELSE

      .....

       

      Error from above: The 'MAKEDATE' function cannot be applied to table calculations and fields from multiple data sources

       

       

      Can anyone suggest the correct syntax or an alternative approach?

       

      Many Thanks

        • 1. Re: Date Calc Query
          Deepak Rai

          Can you attach workbook and what you trying to do in 2-3 lines?

          • 2. Re: Date Calc Query
            Darren Gage

            Sorry, I'm not able to attach anything I'm afraid - apologies if my description is not clear enough.  To try to make it clearer I'm trying to:

             

            Take a date, add a number of months to it based on an indicator from the same data set, that is used to look up the appropriate number of months from a second data set.  Once this is done I need to update the newly calculated date to the last day of the year that is reached once the months are added. Simple??!!

             

            Hope this helps you to help me.....

             

            Thanks