{"id":5637,"date":"2022-07-26T14:31:57","date_gmt":"2022-07-26T14:31:57","guid":{"rendered":"https:\/\/www.stl-training.co.uk\/b\/?p=5637"},"modified":"2023-12-31T00:07:58","modified_gmt":"2023-12-31T00:07:58","slug":"create-field-parameters-in-power-bi","status":"publish","type":"post","link":"https:\/\/www.stl-training.co.uk\/b\/create-field-parameters-in-power-bi\/","title":{"rendered":"Create Field Parameters in Power BI"},"content":{"rendered":"<p>Why is <a href=\"https:\/\/www.stl-training.co.uk\/syl\/205\/microsoft-business-intelligence-advanced-training-courses.html\">Power BI<\/a> taking over the world? Why are so many organisations currently implementing Power BI? Power BI is the most efficient tool to manage business intelligence in a world where the data sets are getting bigger and bigger. The importance of making quick and correct decisions is a key factor in running a successful business. Microsoft constantly improves Power BI. \u00a0In this blog, we will show you how to create Field Parameters in Power BI.<\/p>\n<p>&nbsp;<\/p>\n<p>The \u2018<a href=\"https:\/\/www.linkedin.com\/pulse\/field-parameters-power-bi-report-server-anandakumar-varatharajah?trk=pulse-article_more-articles_related-content-card\">Creating a Field Parameter<\/a>\u2019 tool can create a dynamic visual in few seconds, increasing your productivity. This gives the audience interactive options to choose which information they want the visual to display. In the past, we needed to write DAX expressions to achieve this.<\/p>\n<p>In the following example you will see how this is done by creating a table and writing DAX expressions. DAX (Data Analysis epression) is essential to all Power BI reporting and data modelling developers. STL has a one day DAX course for all who need to write DAX in Power BI desktop.<\/p>\n<h5>Field Parameters done with DAX<\/h5>\n<p>Firstly, you need to create a table. Click Enter Data from the Home tab. In the first column, enter the names of the measures you want to be able to select from a slicer. The slicer will change the visual. Add a second column to create an index (see image below). Name the table at the bottom of this dialog box.<\/p>\n<p><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP1.bmp\"><img decoding=\"async\" class=\"alignnone wp-image-5661 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP1.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"900\" height=\"485\" \/><\/a><\/p>\n<p>Create a Slicer visual and add the Measure column from the created table to the field (see image below).<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-5666 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP2.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"903\" height=\"357\" \/><\/p>\n<p>Now it is time to run the DAX measure. You can use the logical Switch function to return the measure selected from the slicer.<\/p>\n<p><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP3.bmp\"><img decoding=\"async\" class=\"alignnone wp-image-5669 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP3.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"903\" height=\"216\" \/><\/a><\/p>\n<p>The logic in the DAX measure is in the image below. The Switch function will test the value selected from the slicer. If the index value is 1 (Sales), it returns the Sales measure, if the index value is 2 (Profit) it returns the Profit measure. Index value 3 (Sales Cost) returns the Sales Cost measure.<\/p>\n<h5><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP4.bmp\"><img decoding=\"async\" class=\"alignnone wp-image-5672 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP4.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"903\" height=\"390\" \/><\/a><\/h5>\n<h5>Creating a visual to show the selected measure from the slicer<\/h5>\n<p>The visual (a line chart here) header will not show the selected measure from the slicer, but you can create one by writing another DAX measure.<\/p>\n<p>Visual Name=SelectedValue(slicer1[measure],\u201dSales\u201d)<\/p>\n<p>This measure will get the selected value (measure name) from the slicer. If nothing is selected from the slicer, it will return the alternate result \u2018Sales\u2019 by default.<\/p>\n<p>Now you can use the measure to create a dynamic title for the visual. With the visual selected, you will find the title under the formatting options. Next to the title there is an fx button. When you press the fx button, you can use the measure to create a dynamic title.<\/p>\n<p><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP5.bmp\"><img decoding=\"async\" class=\"alignnone wp-image-5674 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP5.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"903\" height=\"433\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Clicking fx will open the dialog box where you can select the measure which creates the dynamic visual header.<\/p>\n<p><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP6.bmp\"><img decoding=\"async\" class=\"alignnone wp-image-5676 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP6.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"793\" height=\"563\" \/><\/a><\/p>\n<p>The visual will now display the selected value from the slicer as a title!<\/p>\n<p><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP7.bmp\"><img decoding=\"async\" class=\"alignnone wp-image-5678 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP7.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"903\" height=\"488\" \/><\/a><\/p>\n<h5>Now to do something similar with the new tool &#8211; Creating a field parameter<\/h5>\n<p>The new tool we got in the May version of Power BI is a preview feature but will soon be a permanent tool.<\/p>\n<p>Firstly, you will have to enable the tool called\u00a0<strong>Field parameters<\/strong>:<\/p>\n<p><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP8.bmp\"><img decoding=\"async\" class=\"alignnone wp-image-5680 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP8.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"584\" height=\"566\" \/><\/a><\/p>\n<p>Then, to create a new field parameter, you will need to navigate to\u00a0<strong>Modeling<\/strong>\u00a0&gt;\u00a0<strong>New parameter<\/strong>\u00a0&gt;\u00a0<strong>Fields<\/strong><\/p>\n<p><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP9.bmp\"><img decoding=\"async\" class=\"alignnone wp-image-5682 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP9.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"903\" height=\"393\" \/><\/a><\/p>\n<p>To build the parameter, you need to provide a name for the parameter and select the fields you want to use. You can select different dimensions (fields from different tables across your data model) or different measures. The example below starts with different dimensions.<\/p>\n<p><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP10.bmp\"><img decoding=\"async\" class=\"alignnone wp-image-5684 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP10.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"668\" height=\"646\" \/><\/a><\/p>\n<p>From a slicer, select the fields you would like to filter on the visual. If you keep the tick in the bottom left corner, you will create a slicer with the dimensions.<\/p>\n<p>The <strong>Field parameters <\/strong>feature will write DAX code to make the slicer and the data model understand what you want.<\/p>\n<h5>The DAX code for this example<\/h5>\n<p>Filter by dimensions = {<\/p>\n<p>(&#8220;ClientName&#8221;, NAMEOF(&#8216;tblClients'[ClientName]), 0),<\/p>\n<p>(&#8220;Category&#8221;, NAMEOF(&#8216;tblProducts'[Category]), 1),<\/p>\n<p>(&#8220;SalesRep&#8221;, NAMEOF(&#8216;tblSalesRep'[SalesRep]), 2)<\/p>\n<p>}<\/p>\n<p>The slicer will display the field names from your data model. If you want more user-friendly names from the slicer, you can amend the code.<\/p>\n<p>Filter by dimensions = {<\/p>\n<p>(&#8220;Client&#8221;, NAMEOF(&#8216;tblClients'[ClientName]), 0),<\/p>\n<p>(&#8220;Product Category&#8221;, NAMEOF(&#8216;tblProducts'[Category]), 1),<\/p>\n<p>(&#8220;Sales Rep&#8221;, NAMEOF(&#8216;tblSalesRep'[SalesRep]), 2)<\/p>\n<p>}<\/p>\n<h5>Adding or removing fields after creating the Field Parameters slicer<\/h5>\n<p>Filter by dimensions = {<\/p>\n<p>(\u201cSales Rep\u201d, NAMEOF(\u2018tblSalesRep\u2019[SalesRep]), 0),<\/p>\n<p>(\u201cProduct Category\u201d, NAMEOF(\u2018tblProducts\u2019[Category]), 1),<\/p>\n<p>(\u201cClient\u201d, NAMEOF(\u2018tblClients\u2019[ClientName]), 2),<\/p>\n<p>(\u201cMonth\u201d,NAMEOF(Dates[Month Number]),3)<\/p>\n<p>}<\/p>\n<p>In the example above, the Month Number field has been added by amending the DAX code. The slicer will now give the report\u2019s audience the option to break down the visual by month.<\/p>\n<p><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP11.bmp\"><img decoding=\"async\" class=\"alignnone wp-image-5686 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP11.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"903\" height=\"482\" \/><\/a><\/p>\n<h5>Using the Field Parameter tool to break down visuals by measures<\/h5>\n<p>You can mix and match different measures and dimensions within the same parameter. For example, you can use this feature to create a dynamic table where the columns can be either measures or dimensions.<\/p>\n<p>As shown below, when you use the new Field Parameter feature, the title of the visual will display the selected fields from the slicer. Again, you will not have to write a DAX measure to do this. It can be this easy to create Field Parameters in Power BI.<\/p>\n<p><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP12.bmp\"><img decoding=\"async\" class=\"alignnone wp-image-5688 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP12.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"619\" height=\"609\" \/><\/a><\/p>\n<h5>Using a field parameter to control visual properties<\/h5>\n<p>Once you have created the field parameters, you can use them to control the measures or dimensions used in a visual.<\/p>\n<p>You can use the parameter in the field drop zones for a visual.<\/p>\n<p><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP13.bmp\"><img decoding=\"async\" class=\"alignnone wp-image-5690 size-full\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2022\/07\/FP13.bmp\" alt=\"Create Field Parameters in Power BI\" width=\"903\" height=\"351\" \/><\/a><\/p>\n<h2>Conclusion<\/h2>\n<p>The new Field Parameter feature is an efficient way of creating very dynamic visuals. It reduces the number of pages needed for the report to give the audience proper business intelligence. This is, then, how to create Field Parameters in Power BI for your reports.<\/p>\n<h1>For more information, please see STL\u2019s two-day Power BI Modelling, Visualisation and Publishing course.<\/h1>\n","protected":false},"excerpt":{"rendered":"<p>Why is Power BI taking over the world? Why are so many organisations currently implementing Power BI? Power BI is the most efficient tool to manage business intelligence in a world where the data sets are getting bigger and bigger. The importance of making quick and correct decisions is a key factor in running a [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[637,23,650,18],"tags":[],"class_list":["post-5637","post","type-post","status-publish","format-standard","hentry","category-application","category-data-visualisation","category-power-bi","category-technology"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/posts\/5637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/comments?post=5637"}],"version-history":[{"count":19,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/posts\/5637\/revisions"}],"predecessor-version":[{"id":5696,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/posts\/5637\/revisions\/5696"}],"wp:attachment":[{"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/media?parent=5637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/categories?post=5637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/tags?post=5637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}