Today, I’ll show how you can control totals and subtotals in your matrix visual in Power BI. This is a problem posted by one of our members at the Enterprise DNA forum wherein the user wants the columns to look Continue reading “Controlling Totals and Subtotals In Power BI”
Tag: Power BI
How We Built A Dynamic Learning Map Recommendation Application In Power BI
For today’s video. I’m going to share something that we’ve been doing internally over at Enterprise DNA. I’d like to mainly showcase a couple of things – how amazing Power BI is to build world-class, dynamic and customizable applications, as Continue reading “How We Built A Dynamic Learning Map Recommendation Application In Power BI”
How To Fix Matrix Totals In Power BI
For this tutorial, I’m going to show how you can fix matrix totals in Power BI, particularly fixing totals and subtotals if the measures you create don’t produce the right results originally. I want to tackle this problem as it Continue reading “How To Fix Matrix Totals In Power BI”
Best Practice Recommendations For Setting Up Power BI Workspaces – Deployment Tips
For today’s video, I’m going to share some best practices on how I think is the best way to setup your Power BI Workspaces. What I found from conversations within the community is that there is still a lot of Continue reading “Best Practice Recommendations For Setting Up Power BI Workspaces – Deployment Tips”
How To Create Custom Dimensions And Groups To Your Filtering Tables Fast In Power BI
For today’s video, I want to show a simple but highly effective technique to create additional filtering, and dimensions to filter by in your Power BI report. There are a number of places where you can add different dimensions Continue reading “How To Create Custom Dimensions And Groups To Your Filtering Tables Fast In Power BI”
How To Use Standard Theming In Power BI Reports
For this tutorial, I’d like to continue my examination of theming in Power BI reports. In my experience, the majority of examples you can find online demonstrates the use of the built-in colour themes or the creation of custom colour Continue reading “How To Use Standard Theming In Power BI Reports”
Financial Reporting Techniques For Power BI – Complete Table Customization Tips
For today’s video, I’d like to go over a little bit of financial reporting. I’ve already created a few videos for this back in a couple of years now, so I think it’s time for an update. I want to Continue reading “Financial Reporting Techniques For Power BI – Complete Table Customization Tips”
Looking For Design Inspiration For Power BI – Advance Visualization Techniques Course Sample
In this video, I’ll talk about how you can look for design inspirations for your Power BI reports. Making reports on a regular basis can be draining creatively. It’s normal to run out of ideas so I want to share Continue reading “Looking For Design Inspiration For Power BI – Advance Visualization Techniques Course Sample”
Emergency Services Analytics – Power BI Challenge #14 Has Launched!
The Power BI Challenges have been the best learning experience for our Enterprise DNA members and even for non-members who join our challenges. Our aim is to bring you great scenarios and data problems which would resonate with an industry Continue reading “Emergency Services Analytics – Power BI Challenge #14 Has Launched!”
Introduction to Enterprise DNA Power BI Accelerator
We’re happy to announce that we’re rolling out a new initiative within the Enterprise DNA community — the Power BI Accelerator! One of the things we’ve learned, both through research and experience, is that while you can learn a lot by Continue reading “Introduction to Enterprise DNA Power BI Accelerator”
Solved: Pass a Parameter to a SQL Query in Power Query
I’ve done a fair amount of research around dynamic and parameterized queries, specifically around an Excel query parameter, as in trying to pass a parameter to a SQL query in Power Query. After much trial and error, I finally have found a solution that works. Here’s the quick and easy way to do this and harness the power of query folding. This solution works in Excel – the process is a bit different in Power BI.
Please note that this post assumes you are at least moderately familiar with Power Query and SQL querying. Your mileage may vary depending on your situation.
In my example, “SParameter” is the name of the parameter I am using, and it represents a store number (retail location identifier). The related field in my SQL table is [Store].
Create the parameter:
- Add a table, with a single record and column. This can be on any tab in your workbook.
- Add this table into Power Query by selecting the table, then Data > From Table/Range. When the query editor opens, if necessary, change the data type (in my case I need it to be text).
- Right click on the record and select “Drill Down”. Since you have only a single record, this step will automatically create a parameter.
- In the properties, I name this SParameter (you may enter the name of your choice for your parameter). Note that the name is case sensitive.
Create the SQL query:
Build your SQL query as normal, but note that we are not going to put a where clause in referencing the new parameter here (see “Why Not Include the Parameter in the SQL Statement” section below). Here’s my simple query example – notice that I’m not including the store field in the criteria section of the query though this is the field my parameter will ultimately filter on.
Select * FROM Storelist WHERE OpenDate < GetDate()-365
If you think like me, you may be pausing here – my table has millions of records and I don’t want them all pulling in – don’t worry, this is the beauty of the process.
- Write your SQL statement in Power Query as noted above.
- When the Query Editor returns the columns and record sampling, for the field you will be using your parameter, filter with any single value (Text Filters > Equals). This is simply a placeholder, to create the Power Query M formula for the next step.
- You will now see that filtering in the formula bar.
- Replace the placeholder value with the name of your parameter, removing any quotes from the placeholder. This is how it looks for me: = Table.SelectRows(Source, each [Store] = SParameter).
- Power Query is smart enough to modify its native query to use the parameter, so it’s not going to pull in the millions of records and then filter after the fact. Success!! This is the power of Query Folding!
- Side note – if you are wondering about GetDate(), this is the SQL current system date, so in a way this is technically a dynamic parameter as well. In my case, the query will only return stores with an open date that is older than 365 days based on today’s date. You may find this useful for your query as well.
Why Not Include the Parameter in the SQL Statement?
In the SQL statement, logic would lead us to add the store number/SParameter as part of the criteria in the select statement. It may seem counter intuitive, but we cannot successfully put the parameter directly into the SQL code/query. I have tried several times, but the challenge is that you are combining data sources and at this time, this is not allowed due to the built in security (SParameter portion is local, SQL portion is external).
If you are tempted to test this yourself, the format would be Select * FROM Storelist WHERE Open < GetDate()-365 and Store = “&SParameter&”. You will likely run into this error “Formula.Firewall: Query ‘SParameter (2)’ (step ‘Filtered Rows’) references other queries or steps, so it may not directly access a data source. Please rebuild this data combination.”
I truly hope this post helped you out. If so, please feel free to leave a comment below letting me know so, and if you’d like, add what you’d like me to cover in a future post. Also, feel free to share this with someone else who may find it useful.
Please bookmark and subscribe to my blog! I am always curating and adding new, relevant content! Thanks so much!
Also, be sure to check out Dose for Excel (click image below)! Add over 100 functions to Excel to increase your productivity and more! They have a free trial right now, so you can try it out today! Disclosure: this is an affiliate link, so I may earn a small commission if you decide to purchase the add-in. Thanks for supporting my blog!
Enterprise DNA Learning Summit – November 2019, Developing Enterprise Apps
EVENT DETAILS – https://ift.tt/2q8z6Ni
Session 4 – Developing Enterprise Apps
The Power BI Online Service has gone through a huge upgrade recently and finally, there is a lot more clarity around how each different feature should be used. During this workshop, we’ll cover how to create compelling apps for your teams and organisations. We’ll also go over many of the new and interesting upgrades that have been created in the web-based platform for Power BI.
• Learn how to build effective app workspaces
• Scale the Power BI online service within your teams
• Manage multiple different reports and insights effectively
• Refresh your enterprise distribution strategies for insights