Hello All,
I've a query like below
SELECT PRD_DATE, Count(DISTINCT PRD_AMT), Sum(PRD_TAX) AS TAX FROM PRODUCT WHERE REL_DATE= '2023-06-25' AND PROD_ID = '123' AND PRD_DATE<= '2023-06-25' AND PRD_DATE >= '2023-06-19' (this should be 7 days back from REL_DATE) GROUP BY 1
Here I want to update the REL_DATE and PRD_DATE dynamically (updating any specific date other then '2023-06-25') using the excel file so that I can also schedule it in the server.
Please advise.
NOTE - I can't use current date as there are chances that the data might not be available for that date. Hence I want to update the particular date
BR
Swapsingh
@swapsingh2712 if your SQL query that is being brought in is done through an Input or In-DB tool, you can add Date tools (Interface tool palette) to your workflow and then dynamically change those parameters.
Once you add Date tools to your workflow, the Action tool will appear for both connections. In your Action tool, you can then choose to update specific portions of your query.
Below is a similar post I had responded to that'll accomplish what you need:
@rzdodson Thank you for the response. Actually I want to schedule this workflow in the server so that it'll run automatically. If I add the interface tool, every time I've to give the input. Is it possible to update the query using excel file?
@swapsingh2712 I think it is possible, assuming that the Excel file is stored in a way that the Server-based workflow can retrieve. Although, I don't think this would solve your dilemma necessarily, as the SQL query would functionally run before Alteryx has the ability to influence the results of your query.
If you do not want to utilize interface tools at all, there are two other options you can take (at the minimum): using a Find and Replace/Filter combination, or 2) an Append/Filter option.
Option 1: Find and Replace/Filter combination
This option would save your SQL query as a string field in Alteryx. From there, you can add a Find and Replace tool that will pass in the Start Date and End Dates and have it change those components of your SQL query. Then, you'll have to develop a batch macro that will pass in the SQL query syntax in order to update the query's script before rendering its results. If you had multiple queries that needed to be run, this can be a useful approach. You would functionally be able to create a batch process to run multiple SQL queries from one workflow, rendering results to where you need them saved. Additionally, you can have each query's output pass through a Filter tool that tests your date field against the established range of your Start and End Date.
Option Two: Append/Filter option
I would recommend this option if the query's initial date range doesn't have to change, but the extract you are pulling from a specific data set changes. Good example would be you want to output all records over the last two years; but, today's analysis only needs to look at the previous quarter. To set this up, you need to create that Excel file that has its Start Date and End Date values in there. Then you combine the results of your SQL query with your Excel file using an Append tool. Similar to the above, you would then add a Filter tool to filter for records within a particular range.
Hope that helps, @swapsingh2712!
To dynamically update the REL_DATE and PRD_DATE in your query based on an Excel file, you can use Alteryx's dynamic input tools and workflow parameters. Here are the general steps to achieve this:
Input Tool for Excel File:
Workflow Parameters:
Filter and Formula Tools:
Update Query with Dynamic Dates:
Example Formula for Dynamic Dates:
Modified SQL Query:
Now, when you run the workflow, you can provide the dynamic dates using the Excel file, and the SQL query will be updated accordingly. This approach allows you to schedule the workflow on the server, and each time it runs, it dynamically adjusts the dates based on the values in the Excel file.
@Hammad_Rashid Thank you for your response. Actually I'm not able to find the option set parameter in my alteryx. I'm using 2021.1 version. Do you have any example workflow which I can follow for my reference
User | Count |
---|---|
18 | |
14 | |
10 | |
6 | |
6 |