How would I add a WHERE clause to a SQL or Access Data Source in Power BI? - powerbi

I am evaluating Power BI as a possible tool for publication quality reports that will be distributed to clients. My source databases are in Microsoft SQL and Access.
I am somewhat confused by the Power Query Editor.
As a part of this, we will need to be able to specify the value of a Client Id field and apply a WHERE clause to the SQL and Access data source.
I see that I can filter data on one or more columns. This would be cumbersome if generating reports for a set of individual clients.
I see a Manage Parameters feature on the Home Tab of the Power Query Editor. Can these parameters be compared to values in database tables?
Are there examples of using M or DAX (or anything else) to implement an equivalent WHERE clause?
Do I have to run stored procedures, populate temporary tables and then run Power BI reports?

Here are a few options:
Connect to your database using a Native Database Query. (Related post.)
Connect to a view you create on your database that includes the WHERE clause.
Filter the table in the Query Editor after connecting to it.
Import or DirectQuery the whole table and filter at run time.
In #3, basic filtering usually gets folded into the under-the-hood query that Power BI sends to the database so that this is similar to #1 as far as your database sees.
With #4, it's possible to apply row-level security so that different people have access to different subsets of the data.

Related

Create PowerBI Datamart from Azure Analysis Service

I am trying to create PowerBI Datamart from Azure Analyis service. There is a datamodel available in the Azure Analysis Service and I can connect using URL and Database Name. The datamodel has ~100 tables present in it and relationship also setup. So my question is, if I want to create a PowerBI datamart from the Azure Analyis service datamode, I need to do the Get Data option of PowerBI datamart and connect to Azure Analyis service, select table, select fields 100 time for getting all the tables of Azure Analyis service datamode into my PowerBI datamart? Is there any import function available where I can import all the tables in a single time?
Why do you want to copy data from AAS into a database?
The reason you find it difficult is that it's an odd thing to do. The query designer for AAS/SSAS generates MDX queries which are indented to run aggregate queries that return a handful of rows, and are wholly unsuitable for extracting whole tables. If you try, the queries will just run forever and fail.
It's possible to extract data from AAS/SSAS tabular models, but you must use DAX not MDX, and so you need to the Power Query or "Transform Data" window, and use the advanced editor.
Each query to load a table should look like this, eg to load the 'Customer' table:
let
Dax = "evaluate Customer",
Source = AnalysisServices.Database("asazure://southcentralus.asazure.windows.net/myserver", "mydatabase", [Query=Dax])
in
Source

Power BI Paginated report using power BI dataset from multiple azure sql servers

Just looking for a pointer as to the best way to go about this.
I'm comfortable with Power BI Report Builder (SSRS experience), but am pretty much a Power BI novice.
Basically, we have to create a Paginated (non-interactive) report for client consumption. It's going to be large, have multiple datasets, and use parameters / presence of data in the data sets to group data and/or turn sections on or off.
Not too much visualisation - some illustrative graphs and tables here and there - and quite a bit of text, some of it with data / text inserted via placeholders from the various datasets.
There are 3 Azure SQL databases I need to combine data from for this, (split roughly into config, data and results).
In SSRS / SQL Server, I would have used one of my databases as the data source, and written a stored procedure per SSRS data set, joining to tables in other databases in the stored procedure query.
Then in Report builder just set up the data sets joining to the stored procs and gone from there.
On Azure SQL Server, I think I've got 2 options:
write elastic queries so I can bring in the data I need from each database, but just query on one database.
Build a Power BI Model / Dataset that joins the relevant tables from the 3 databases together, publish to power bi service and use that as my datasource.
What's the best solution for my reporting scenario?
Cheers

How is the user defined aggregations different to having a table aggregated via sql/power query in import mode?

I'm exploring the concept of aggregations in Power BI.
I understand that the auto feature is only available when the corresponding table is in direct query mode. Where as manual aggregations is supported for import as well as direct query mode.
Effectively we can write an aggregate group by SQL Query to fetch the data and load it into an aggregate table in import mode.
I'm unable to understand how this helps because since the aggregate table is in Import mode, the source database table will need to be queried at each data refresh. So what problem does aggregates solve?
the source database table will need to be queried at each data refresh.
But the source database table will not need to be queried for each visual render. Visuals render for each user on load and on any change to another visual (like selecting in a slicer, or cross-highligting in a chart). In pure DirectQuery every visual render sends a DAX query, which translates to one or more SQL queries.
SQL queries over large fact tables can require many seconds of CPU time in the source, where the same DAX can read an in-memory aggregation table in a few milliseconds.
So the problem it solves is to reduce the number of queries to the source from report users. Typically you create aggregates that satisfy the initial views of reports and dashboards, and the most common slicers and filters used by the reports.

What is the approach to merge data from multiple databases (same schema) using Power BI?

I have 3 OLTP databases, all using the same database schema. Each db represents one department.
I am exploring Power BI as a solution for reporting at the company level, so all departments combined.
What is the approach to combine data from multiple dbs into a data warehouse? For example - do I need SSIS to combine the 3 dbs into 1 data warehouse?
Another option could be to have 1 shared dataset per db, and then the final report can connect and combine multiple live datasets? Or is there another way with Power BI like combining multiple live datasets?
Any reference link on how if someone has done this?
Or is there another way with Power BI
Yes. Simply create a single import model and load data from all three databases in it. So for each table in your Power BI model you would have three Power Queries set to not load into the model, and you would append them in a query that is used to load your model. See eg: https://learn.microsoft.com/en-us/power-query/append-queries
Best practice would be to:
Extract the data into a single database (DWH or reporting schema)
Build the necessary items there for your data model, be it reporting schema, or star/snowflake schemas
Connect Power BI to that schema.
Combining datasets is going to be tricky, you may have the same measures in each of the datasets. Combining in the database, with any added columns to indicate the department is the best option in terms of supporting updating/adding/removing items. For example, if the schema changes in the DB's you do it in one place, not three datasets. The toolset in DB/SSIS will be better suited to the heavy lifting of the data to a location.
You would use SSIS to extract the data if on-prem data, Azure Data Factory for Azure DB's. Extract to a staging schema, convert/transform the data into its final from, with a new schema to define what it is, facts/dimensions other schema names such as reporting can be used, depending on the data model you wish to build. Most of this is covered by the standard ETL pattern of OLTP to an OLAP database.

programmatically change dataset SQL statement in power bi

Is it possible to change SQL statement of the dataset via API call?
My Scenario: I have data in multiple tables in SQL Server. I have created a SQL query with joins to fetch the required data. I created a SQL server dataset by providing that query in the SQL Statement section and published it on the Power BI workspace. Now, I want to modify that SQL Statment programmatically.
I want to import this same .pbix file to create different datasets. The Idea is to use import date set api to import this dummy dataset and then programmatically change the db source and the SQL Statment, to customizes it for my different report need.
Any pointer or help is much appreciated.
For server name and database name, you can simply use parameters. Click the button to the left of the field to do this. You can make some changes in the query using parameters too, but this isn't very flexible. This can be done by defining text parameter and using it in in the M statement associated with the dataset’s Source step. For more information you may see this article:
https://www.red-gate.com/simple-talk/sql/bi/power-bi-introduction-working-with-parameters-in-power-bi-desktop-part-4/
Then you can use the Rest API to modify parameter values and refresh your datasets. You will need Update Parameters In Group and Refresh Dataset In Group API calls.
At of this writing, this is not supported by the Power BI REST API.
Possible workaround: Given you're using SQL Server, I'd suggest you create a VIEW in SQL Server with the statement you defined in your Power BI report, and change your report to point to that view instead.
Then, to modify the SQL statement, you just have to ALTER the view in the database.