This video shows the way of accessing Azure Databricks Notebooks through Azure Data Factory. Additionally, it explains how to pass values to the Notebook as parameters and how to get the returned value from Notebook to Data Factory Pipeline.
Showing posts with label Parameters. Show all posts
Showing posts with label Parameters. Show all posts
Friday, June 5, 2020
Wednesday, June 21, 2017
Power BI Parameters - What are they and when they can be used?
Microsoft Power BI supports adding parameters for queries and use them with various areas. However, since it has some limitations and cannot use with all areas, it has not been noticed much. Let's talk about Power BI parameters and see the way of using it.
Let's take a scenario and see how parameters can help on that. I have a set of CSV files that shows monthly sales. We need to to create a report using one of the files and then publish. Whenever the report needs to be refreshed for a different file, I need to change the data source by changing many things. What if I can just open the report using Power BI Desktop and change the source using a menu and get the report refreshed rather changing many things?
It can be done with Power BI Parameters. We can create a parameter with predefined values (in this case, source file names along with paths) and use it for changing the source.
Power BI Parameter can be created in three ways;
- Parameter that accepts a value via an input box
- Parameter that is formed using a predefined list
- Parameter that is formed using another query
Parameter with a predefined list
Let's focus on the second one first. Here are the steps for creating a Power BI report with a parameter;
1. Open Power BI and connect with a CSV file. In my case, the file name is Sales_201501.csv.
2. Once the file is loaded, click Edit Queries in Home ribbon for opening Query Editor. You should one query under Queries.
Parameters can be created only with Query Editor. However, created parameters can be accessed in both Query Editor and Data Model.
3. Click Manage Parameters in Home ribbon. Once the dialog box is opened, click New to create a new Parameter.
4. Name the parameter as SourceFile.
5. Select Text for Type.
6. Select List of values for Suggested values.
7. Enter File Names along with paths.
8. Set Default Value as you need. This is the default value for the designer.
9. Set Current Value as you need. This setting is for the end user, or to use with the report level.
Now you should see the parameter in Queries. If you want to open it as another table in the data model, you can right click on it and select Enable Load. We do not need to enable this option for using the parameter at report level.
Now we need to make sure that source of our file is set with the created parameter. There are two ways of doing it. One is open the Advanced Editor and change M Code. Other way is, using Data source settings. Let's use the second option. If you need to know how the M Code is getting changed, open it and see after the change.
10. Click Data source settings in the Home ribbon. This opens the Data Source Setting dialog box.
11. Select the source and click Change Source.... This opens a dialog box that allows you to change settings related to your source.
12. You should notice that the button given for File Path has an option for creating parameters and selecting a parameter.
13. Select Parameter as the option and select name parameter created.
14. Click OK and close the Data source settings.
15. All set. Click Close & Apply for saving the queries and closing Query Editor.
16. Create a visual as you can distinguish results when different file is selected. This is what I created from my file.
Let's change the source using the parameter now.
17. Click down-arrow in Edit Queries in Home ribbon. You should see three options. Select the last one that is Edit Parameter.
18. You should see Enter Parameters dialog box that shows all parameters. Change the source file to different one.
19. Once clicked OK, you should be prompted for Applying. Apply the settings and you should see the report with new source now.
Like this way, we can use the parameter in other sections like Filtering rows in Query Editor, Replacing, etc. We still cannot use the parameter with DAX and it is one limitations.
Wednesday, July 15, 2015
MDX and Reporting Services: How to remove duplicates from a parameter?
What if you get duplicate values from a dimension that is going to be used for loading a Reporting Services parameter? Generally, you do not get duplicates from a dimension because we do not configure the dimension like that. For an example, we do not expect duplicate names from Product dimension. But there can be an exception that shows duplicate names but unique keys, something like below;
Id | Name | ... |
---|---|---|
1 | Product A | ... |
2 | Product B | ... |
3 | Product A | ... |
4 | Product C | ... |
If Id of this has been used as the key and name has been used as the name of the key, even though we write a MDX query like below, we still get duplicates as they have unique keys.
SELECT { } ON COLUMNS, { Distinct([Product].[Product].MEMBERS) } ON ROWS FROM [Cube];
Best way is, fix this in database level without taking it to reporting level. But if we cannot do anything at database level (assume that no permission, have to use as it is) and still should not show duplicates with the parameter, what is the best way?
I have solved this in two ways. One is, execute the MDX from the database engine, connecting with OLAP database using a linked server. In this case, TSQL SELECT statement will be used and source for the parameter will be database engine, not OLAP database.
SELECT DISTINCT [Measures.ProductName] FROM OpenQuery(LinkedServerForOLAP, 'WITH MEMBER [Measures.ProductName] AS [Product].[Product].CurrentMember.Name SELECT { [Measures.ProductName] } ON COLUMNS, { Distinct([Product].[Product].MEMBERS) } ON ROWS FROM [Cube]')
Other method is, write VB.Net code inside the report for removing duplicates. This requires a hidden parameter that holds data coming from the OLAP database and another new parameter for showing values. New parameter has to be loaded from a function written in the Code segment that accesses the hidden parameter for getting values, programatically removes duplicates and returns distinct values.
Here is the second way;
First create a hidden parameter. Make sure it is set as hidden.
Then set Available Values and Default Values with the data set created based on OLAP database.
First part is done. Then implement the following code in Code segment.
Function GetDistinctLabels(parameter As Parameter) As String() Dim labels As Object() = parameter.Label System.Array.Sort(labels) Dim x As Integer = 0 For i As Integer = 0 to labels.Length - 1 If i > 0 And labels(i).Equals(labels(i - 1)) Then Continue For End If labels(x) = labels(i) x += 1 Next Dim distinctlabels As [String]() = New [String](x - 1) {} System.Array.Copy(labels, 0, distinctlabels, 0, x) Return distinctlabels End Function
After that, load the main parameter that is used for showing values as below;
Set the Available Values using Specify values and call the function written for loading distinct values passing parameter name. Do it for both Label and Value.
Set Default Values using same technique if required.
That is all. I have used both methods and both worked fine. However if keys of these labels have to be passed to another dataset loading more data, additional work is required for maintaining keys of the parameter.
Wednesday, May 6, 2015
How to check parameters values used for compiling the stored procedure?
It is a known fact that the initial plan of the stored procedure is created with its first execution. SQL Server engines creates the plan based on the values passed for parameters with stored procedure's first execution and places the plan in the cache. This plan will be reused with consecutive executions regardless of the values passed to parameters. This behavior is called as Parameter Sniffing, and it helps to improve the overall performance of the stored procedure's execution as well as downgrade the performance of it. For more info on this, read one of my old post: Do we need to recompile Stored Procedures when an index is added or parameter value is vary greatly?
With consecutive executions, if you want to see the values that have been used for compiling the procedure, or in other words, parameters values used for the plan in the cache, what is the easiest way of seeing it? Simplest way is, get the Properties of last component in the plan and see Parameter List property. Here is the way of doing it;
First, let's create a procedure and execute once.
USE AdventureWorks2014; GO -- Drop if it is exist IF OBJECT_ID('dbo.GetOrderDetails', 'P') IS NOT NULL DROP PROC dbo.GetOrderDetails; GO -- Create the procedure CREATE PROC dbo.GetOrderDetails @Number int AS SELECT * FROM Sales.SalesOrderDetail WHERE SalesOrderDetailID <= @Number GO -- Execute once. This adds the plan which is optimized for -- parameter value 1. EXEC dbo.GetOrderDetails 1;
Now let's execute it with a different value enabling Include Actual Execution Plan.
Open the Execution Plan tab and click on SELECT.
Properties window can be opened by either pressing F4 or Right-Clicking and Selecting Properties. Once it is opened, You will see property called Parameter List and it has the values used for compiling the stored procedure and values used for current execution.
Is this useful? Yes, if you are planning to recompile or want to know whether the plan is optimized for new executions, this holds some of required information you need on it.
Open the Execution Plan tab and click on SELECT.
Properties window can be opened by either pressing F4 or Right-Clicking and Selecting Properties. Once it is opened, You will see property called Parameter List and it has the values used for compiling the stored procedure and values used for current execution.
Is this useful? Yes, if you are planning to recompile or want to know whether the plan is optimized for new executions, this holds some of required information you need on it.
Monday, September 19, 2011
Reporting Services Parameters: Adding “All” item.
There are some instances we have to create parameters with multiple items, including an item representing all items in the list, mostly called as “All”. There are various ways of doing it. If the list is dynamic and data source is OLAP, you get this item automatically. If it is not OLAP, and loading from OLTP database, this item has to be manually added and programmatically handled.
Here is an easy way to handle it. Have this additional item in a new query and use UNION for joining it to main query.
SELECT 'All Years' AS OrderYear
, 0 AS OrderYearValue
UNION
SELECT DISTINCT
CONVERT(varchar(100), YEAR(OrderDate)) AS OrderYear
, YEAR(OrderDate) as OrderYearValue
FROM Sales.SalesOrderHeader
ORDER BY 2
Now data source contains the item. In order to get this handled with query parameter, follow below code;
SELECT {your columns}
FROM Sales.SalesOrderHeader
WHERE YEAR(OrderDate) = @Year
OR @Year = 0
Happy Coding .
Subscribe to:
Posts (Atom)