6 Replies Latest reply on Aug 5, 2016 5:01 AM by Tom W

    Compare current month/year v/s previous year/same month

    Vishal D

      I have below fields in as my fields in database.

      [Report Year] = [2016,2015,2014,2013,2012]

      [Report Month] = [1,2,3,4,5,6,7,8,9,10,11,12]

      [Sales Profit] = [123, 456, 789]

       

      If the user runs the report for today then I want to capture today's month/year and show bar chart comparing sales profit for current month/year v/s previous year same month.

       

      How would I do this?

        • 1. Re: Compare current month/year v/s previous year/same month
          Tom W

          What have you managed to achieve so far? What have you tried?

           

          Please upload a Tableau Packaged Workbook including some sample data to show what you've been able to achieve so we can go from there.

          • 2. Re: Compare current month/year v/s previous year/same month
            Vishal D

            I am connecting to live data which has millions of records. I will have to build some dummy data as I have mentioned above.

             

            Below are the 3 columns in my data set.

            [Report Year] = [2016,2015,2014,2013,2012]

            [Report Month] = [1,2,3,4,5,6,7,8,9,10,11,12]

            [Sales Profit] = [123, 456, 789, etc...]

             

            All the date functions tableau has need date format which I dont have. I have report month & year.

             

            I hope I am explaining my question clearly?

             

            If you still need some dummy data then I will have to create some. Let me know

            • 3. Re: Compare current month/year v/s previous year/same month
              Vishal D

              Attached is the sample data.

               

              I dont want to pull many years data when I need only current month/year and want to compare with previous.

               

              But this is the sample data I have in DB

               

              Let me know if you need further info?

              • 4. Re: Compare current month/year v/s previous year/same month
                Tom W

                For future reference please upload a Tableau Packaged Workbook with your sample data, not just the data.

                I've prepared an example using the Sample - Superstore dataset.

                Since this test dataset doesn't have 2016 data, I created a parameter called parameter_today_date which I can use to pretend the current date is in 2014. You would replace references to this field with a reference to the NOW() function.

                 

                Create a calculated field like follows;

                datetrunc('month',[parameter_today_date]) = datetrunc('month',[Order Date])

                OR

                datetrunc('month',dateadd('year',-1,[parameter_today_date])) = datetrunc('month',[Order Date])

                 

                Drag the field to your filters shelf and set it to true. You now have the sum of sales for last year and this year in the month of August.

                • 5. Re: Compare current month/year v/s previous year/same month
                  Vishal D

                  Hi Tom,

                   

                  Not able to open your example as I am on lower version of Tableau.

                   

                  I want to use [Report Year] & [Report Month] as end user filters. If the user selects [Report Year] = 2016 and [Report Month] = 08 then I want to show [sales] comparison [Report Month] = 08 for 2015 & 2016. Selected Year v/s previous year for same month.

                   

                  Apologies if I am not clear. Appreciate all your help here.

                  • 6. Re: Compare current month/year v/s previous year/same month
                    Tom W

                    Hi Vishal,

                    I'd never know you're on a lower version because you've never uploaded a Tableau Packaged Workbook.

                     

                    I've outlined the calculated field I used in my above example. How about you go ahead and follow those instructions in Tableau and upload what you manage to get done in a Tableau Packaged Workbook.