4 Replies Latest reply on Jul 18, 2018 12:18 AM by Shrey Jain

    Filtering date fields via Speech Recognition in tableau?

    Shrey Jain

      I am using a speech recognition js and a tableau js "tableau_v8.debug.js" to control the tableau filters. when i speak "March 2016" it is passed to the date field function but the data doesnt get filtered as the date in the date field is like 01/03/2016 12:00:00 AM and the tableau is showing the single date for all the dates of March.

       

      any help on this would be appreciated

      Here is my code . I am passing March 2016 to noteContent:

       

      function Date (noteContent)

            {

        var worksheets = activeSheet.getWorksheets();

         for(var i = 0; i < worksheets.length; i++)

         {

      activeSheet.getWorksheets()[i].applyFilterAsync('Date', noteContent, tableau.FilterUpdateType.REPLACE);

           } 

        viz.show();

            }

        • 1. Re: Filtering date fields via Speech Recognition in tableau?
          Patrick A Van Der Hyde

          Hello Shrey,

           

          I moved this to the JavaScript API where other developers are more likely to see this post.  I know that allan.walker.0 did some work with speech recognition as well and may have a contribution to add.  There is a older Think Data Thursday that covers this topic in some degree - Think Data Thursday: JavaScript API UX of the Future - YouTube  and may be helpful.

           

          Patrick

          • 2. Re: Filtering date fields via Speech Recognition in tableau?
            Shrey Jain

            I have tried the below Codes:

             

            function filterDate()

                  {

              var worksheets = activeSheet.getWorksheets();

               for(var i = 0; i < worksheets.length; i++)

               {

               activeSheet.getWorksheets()[i].applyRangeFilterAsync("Date", { min: new Date(Date.UTC(2016, 3, 1)), max: new Date(Date.UTC(2016, 12, 31)) });

             

                 } 

              viz.show();

                  }

             

            Here I have passed hard Coded Date values. The purpose of passing such values is to filter the data for the month of March 2016. But it doesn't work.

            1 of 1 people found this helpful
            • 3. Re: Filtering date fields via Speech Recognition in tableau?
              Shrey Jain

              I have also tried this to pass the date manually ... but this is also not working.

               

              function filterDate()

                    {

                var worksheets = activeSheet.getWorksheets();

                 for(var i = 0; i < worksheets.length; i++)

                 {

                   activeSheet.getWorksheets()[i].applyRelativeDateFilterAsync("Date", {anchorDate: new Date(Date.UTC(2016, 5, 1)),periodType: tableau.PeriodType.YEAR,rangeType:  tableau.DateRangeType.LASTN,rangeN: 1});

                       /

                   } 

                viz.show();

                    }

               

              any help on this would be appreciated.

              1 of 1 people found this helpful
              • 4. Re: Filtering date fields via Speech Recognition in tableau?
                Shrey Jain

                Hi Patrick,

                 

                Thanks for the reply !!

                 

                I Have solved this issue. when we use voice commands then the values that is passed to the applyFilterAsync() function must be a string .  But here applyFilterAsync('Date,noteContent,tableau.FilterUpdateType.REPLACE) , in this Date is a filter that is having a data type of DateTime. So it will not accept any value such as 'March 2018' or 'June 2018' etc. as these are string values. In order to filter Date we will have to make new Calculated field which will accept the string values. So we will have to make a new calculated field from this Datetime 'Date' field as below:

                 

                We will make a calculated field say PERIOD= ( STR(Datename('month',[Date])) + ' ' + STR(Year([Date])))  and put this PERIOD in the filters. and use this PERIOD field as a 'filter' on the top of our Dashboard.

                the PERIOD filter will appear as below:

                 

                and now pass the values through this, for eg  'March 2018' or 'June 2018' etc. it will filter the data. please find the syntax below:

                activeSheet.getWorksheets()[i].applyFilterAsync('PERIOD', noteContent, tableau.FilterUpdateType.REPLACE);

                This will filter any field having 'Month Year' in our dashboard.

                 

                The issue is resolved 

                1 of 1 people found this helpful