ASP.NET Core 5 Microsoft Power BI reports – Visual Studio Magazine

0

[ad_1]

Corner C #

ASP.NET Core 5 Microsoft Power BI Reports

Eric Vogel provides step-by-step instructions for building an ASP.NET 5 Core web app in Visual Studio 2019 and integrating a Power BI report into it.

Today I’m going to walk through how to integrate a Power BI report into an ASP.NET 5 Core web app. We’ll start by creating a new web app, and then I’ll detail how to integrate your Power BI report into it.

We’ll start by creating a new ASP.NET Core 5 MVC web app in Visual Studio 2019 as shown in Figure 1.

Figure 1: Create a new ASP.NET Core 5 MVC web application
[Click on image for larger view.] Figure 1: Create a new ASP.NET Core 5 MVC web application

After that, give the web application a name as shown in Figure 2.

Figure 2: Name your ASP.NET Core 5 application
[Click on image for larger view.] Figure 2: Name your ASP.NET Core 5 app

In the next dialog box, select .NET 5 as target frame as seen in figure 3.

Figure 3: Select .NET 5 Framework
[Click on image for larger view.] Figure 3: Select .NET 5 Framework

Then click on the To create button and you’ll have a new ASP.NET 5 Core web app that has a Razor page named Index.

Now that our web app is created, let’s create our Power BI report. To create a Power BI report, you must create a Power BI account. I will be using a new trial account for our demo report. Note that from now on, you need a work email address to sign up for a Power BI account.

You should now see the Power BI dashboard where we will create a new report as seen in Figure 4.

Figure 4: Power BI dashboard
[Click on image for larger view.] Figure 4: Power BI dashboard

Click on the New report button. You should now see the screen in Figure 5 where you can choose your dataset. Choose the Paste or manually enter data option.

Figure 5: Choose a dataset for our report
[Click on image for larger view.] Figure 5: Choose a dataset for our report

We will now enter test report data into a Customers table as shown in Figure 6.

Figure 6: Creating test report data
[Click on image for larger view.] Figure 6: Creating test report data

Then click on the Automatically create a report button. Power BI will offer some auto-generated reports that aren’t very useful, so we’ll move on to the next step. Datasets tab and select our Customers dataset as seen in Figure 7.

Figure 7: Customer data set
[Click on image for larger view.] Image 7: Customer dataset

On the next page, select the Create from scratch option which will take you to a report creation screen. Enter the parameters seen in Figure 8.

Figure 8: Creation of our report
[Click on image for larger view.] Figure 8: Creation of our report

Our test report simply displays all of our data in a table with drill-through access for the third Status column. We will now save our report via File-> Save report and give our report the name of “Customers” as indicated in Figure 9.

Figure 9: Saving our report
[Click on image for larger view.] Figure 9: Saving our report

We will now publish our report on the web via File-> Embed Report-> Publish to Web as seen in Figure 10.

Figure 10: Publish the Integrate report
[Click on image for larger view.] Figure 10: Publish the Integrate report

Your administrator will need to enable this feature in order to successfully publish your report to the web. If this is your own Power BI account, you can also start a 60-day free trial to enable this feature. You will now see a modal with a link to your report and an iframe code to embed the report into your web application. Copy the iframe code now as shown in Figure 11.

Figure 11: Power BI integration options
[Click on image for larger view.] Figure 11: Power BI integration options

Now it’s time to embed our report into our ASP.NET 5 web application. Open the Index.cshtml file and put this markup:

@{
    ViewData["Title"] = "Home Page";
}

Customers Report

Replace the tag

Figure 12: Viewing our report in our web application
[Click on image for larger view.] Figure 12: Viewing our report in our web application

About the Author

Eric Vogel is a senior software developer for Red Cedar Solutions Group in Okemos, Michigan. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning software architecture and crafts, and is always looking for ways to build more robust and testable applications. Contact him at [email protected].

[ad_2]
Source link

Share.

Leave A Reply