<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by S Logeshkarthik on Medium]]></title>
        <description><![CDATA[Stories by S Logeshkarthik on Medium]]></description>
        <link>https://medium.com/@s.logeshkarthik?source=rss-194959b2fb54------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by S Logeshkarthik on Medium</title>
            <link>https://medium.com/@s.logeshkarthik?source=rss-194959b2fb54------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 07:33:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@s.logeshkarthik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Implementing a Connection to the  Power BI Admin REST API & Storing Historical Data ]]></title>
            <link>https://medium.com/@s.logeshkarthik/implementing-a-connection-to-the-power-bi-admin-rest-api-storing-historical-data-c8ea08a5c083?source=rss-194959b2fb54------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8ea08a5c083</guid>
            <dc:creator><![CDATA[S Logeshkarthik]]></dc:creator>
            <pubDate>Tue, 08 Oct 2024 17:03:03 GMT</pubDate>
            <atom:updated>2024-10-08T17:03:03.584Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*pBZhwDfHixlm0PRiNtynhg.jpeg" /></figure><p>Hello, readers 👋!</p><p>Recently, I encountered several challenges while connecting to the Power BI Admin API. I thought it would be beneficial to share my experience, especially for developers working on similar use cases. This blog covers connecting to the “Admin — Get Activity Events” API, incrementally loading the fetched data, storing the entire history as a delta table, and building a reporting layer on top of it.</p><h3>Agenda</h3><p><strong>🔹 Establishing a Connection to the “Power BI- Get Activity Events” API</strong></p><p><strong>🔹 Incrementally loading data and storing history</strong></p><p><strong>🔹 Reporting on top of a delta table containing historical data</strong></p><h3>Connecting to the Activity Events API</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*ZKgwaErDIOO711rDWFbbrA.png" /></figure><blockquote><strong><em>Note:</em></strong> By default, the Power BI Admin Activity dashboard only displays the last 30 days of history.</blockquote><p>Challenges in Fetching Data from the Admin API</p><p>During API calls, you may encounter unexpected errors if the correct approach is not followed. There are several methods to implement this, but the approach I took proved effective.</p><h3>Approach Taken</h3><p>To access the Admin API, I used a service principal via an Azure app registration and generated an access token. Below is a step-by-step breakdown:</p><ol><li><strong>Register an App in Azure App Registrations</strong></li></ol><ul><li>Ensure that the app is registered by a Power BI Admin.</li><li>Create a client secret for the app, which will be used to access the Admin API.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*Wm8BPj_aewgLhS9_u9k9Sw.png" /></figure><p><strong>2. Add the App to a Security Group in Azure</strong></p><ul><li>Make sure the app is added to a security group in Azure.</li></ul><p><strong>3. Grant Service Principal Access</strong></p><ul><li>Go to the tenant settings and add the security group under the admin API settings choosing the <em>“specific security group”</em> option.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OgggJLPIXIPlBB5ED8bcsw.png" /></figure><p><strong>4. Fetch Data</strong></p><ul><li>Once the above setup is complete, you can call the API in your data engineering notebook to fetch the data.</li></ul><blockquote><strong>Note:</strong> The API allows a maximum of 200 requests per hour. If you encounter issues, review the steps to ensure everything has been correctly followed.</blockquote><p><strong>Python Code for Fetching the Access Token</strong></p><pre># Azure app configurations<br>CLIENT_ID = &#39;&lt;client Id here&gt;&#39;<br>CLIENT_SECRET = &#39;&lt;client Secret here&gt;&#39;<br>TENANT_ID = &#39;&lt;tenant ID here&gt;&#39;<br>AUTHORITY_URL = f&#39;https://login.microsoftonline.com/{TENANT_ID}&#39;<br>SCOPE = [&#39;https://analysis.windows.net/powerbi/api/.default&#39;]<br>API_URL = &#39;https://api.powerbi.com/v1.0/myorg/admin/activityevents&#39;<br><br># Creating a confidential client application<br>app = ConfidentialClientApplication(<br>    CLIENT_ID,<br>    authority=AUTHORITY_URL,<br>    client_credential=CLIENT_SECRET,<br>)<br><br># Acquiring the response and storing it in a variable<br>token_response = app.acquire_token_for_client(scopes=SCOPE)<br><br># Print access token if available<br>if &#39;access_token&#39; in token_response:<br>    access_token = token_response[&#39;access_token&#39;]<br>    print(&quot;Access Token Acquired&quot;)<br>else:<br>    raise Exception(&quot;Failed to acquire access token&quot;)</pre><p>Python Code for Fetching Data from the API Using the Access Token</p><pre>url = f&quot;https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime=&#39;{&lt;start_date&gt;}&#39;&amp;endDateTime=&#39;{&lt;end_date&gt;}&#39;&quot;<br>headers = {<br>    &#39;Authorization&#39;: f&#39;Bearer {access_token}&#39;<br>}<br>all_events = []<br><br>try:<br>    response = requests.get(url, headers=headers)<br>    response.raise_for_status()  <br>    data = response.json()<br><br>    if &#39;activityEventEntities&#39; in data:<br>        new_events = data[&#39;activityEventEntities&#39;]<br>        all_events.extend(new_events)<br>    else:<br>        print(&quot;No &#39;activityEventEntities&#39; found in the response.&quot;)<br><br>    # Handle pagination with continuation token<br>    while &#39;continuationToken&#39; in data and data[&#39;continuationToken&#39;]:<br>        continuation_token = data[&#39;continuationToken&#39;]<br>        next_url = f&quot;https://api.powerbi.com/v1.0/myorg/admin/activityevents?continuationToken=&#39;{continuation_token}&#39;&quot;<br>        response = requests.get(next_url, headers=headers)<br>        response.raise_for_status()<br>        data = response.json()<br><br>        if &#39;activityEventEntities&#39; in data:<br>            new_events = data[&#39;activityEventEntities&#39;]<br>            all_events.extend(new_events)               <br>        else:<br>            print(&quot;No &#39;activityEventEntities&#39; found in the response.&quot;)<br><br>    print(f&quot;Total events fetched: {len(all_events)}&quot;)<br><br>except Exception as e:<br>    print(f&quot;An error occurred: {e}&quot;)</pre><p>In this code, all_events is a list containing all the activity data within the specified time window. This data can be converted into a DataFrame and tailored to any desired format. Later, it can be stored in a delta table and upserted with each new API call.</p><blockquote><strong>Upsert :</strong> The term “Upsert” refers to a database operation that inserts a new record if it doesn’t exist or updates an existing record if it does. This method is essential for keeping the data consistent and up-to-date.</blockquote><h3>Why Incremental Loading ?</h3><p>Since the API only provides the past 30 days of data, implementing an incremental load process into a Delta table preserves historical data. Using the Medallion architecture can optimize the maintenance of this data.</p><h3>What is Medallion Architecture?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gRR479sIqi-J1B0uwqWsuQ.jpeg" /></figure><p>Medallion architecture organizes data into three layers:</p><ul><li><strong>Bronze Layer :</strong> Raw data</li><li><strong>Silver Layer :</strong> Cleansed and Transformed Data</li><li><strong>Gold Layer :</strong> Curated, Master Data</li></ul><p>There are several options for implementing this use case, such as AWS, Azure, Fabric, Databricks, etc. I chose Fabric for implementing this use case.</p><h3>Reporting Layer on Top of the Delta Table Containing All Historical Data</h3><p>Power BI will serve as the visualization tool for this use case. The report can be connected to the Delta table, enabling you to monitor the entire Power BI activity at both the tenant and capacity levels, from the highest to the most granular details.</p><p>This report is highly useful for audit, usage analysis, tracking, and more, based on your needs.</p><p>I hope this blog helps many of you implement a similar use case while overcoming technical challenges.</p><p><em>If you found the above article useful, kindly consider giving it an applause and feel free to connect with me on these platforms:</em></p><p>Follow me on LinkedIn: <a href="https://www.linkedin.com/in/logesh-karthik-273862184/">Logesh Karthik</a></p><p>Follow me on Medium: <a href="https://medium.com/@s.logeshkarthik">https://medium.com/@s.logeshkarthik</a></p><p><strong>Happy coding!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8ea08a5c083" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Large Dataset Handling in Power BI : Best Practices ]]></title>
            <link>https://medium.com/@s.logeshkarthik/mastering-large-dataset-handling-in-power-bi-best-practices-2354bde58125?source=rss-194959b2fb54------2</link>
            <guid isPermaLink="false">https://medium.com/p/2354bde58125</guid>
            <dc:creator><![CDATA[S Logeshkarthik]]></dc:creator>
            <pubDate>Sun, 12 Nov 2023 22:30:01 GMT</pubDate>
            <atom:updated>2023-11-17T14:18:03.172Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mastering Large Dataset Handling in Power BI📊 : Best Practices 💡</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*E7ENnTVysSBA1i-3kDxy9w.gif" /></figure><h3>Let’s start by getting to know a few things about Power BI.</h3><p>Power BI is a powerful visualization tool that addresses a wide range of business needs. It empowers business users to visualize their data in various formats, providing instant insights and supporting better decision-making. Additionally, it enables developers to transform data from diverse sources into insightful visualizations tailored to specific requirements. However, developers may encounter various challenges, such as selecting the right data ingestion strategy and managing large datasets, which can impact report performance if best practices are not followed. In this blog, we will explore best practices for handling large datasets in Power BI, ensuring that your reports run smoothly and efficiently. For Power BI newcomers, this blog will provide insights into how to manage large datasets within the Power BI data model.</p><p><strong>Here are the fundamental steps for creating a Power BI report:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*gJV_tf0JZucsM5FXzsUcCA.png" /></figure><p>Let’s shift our focus to data ingestion, connection modes, and diverse approaches for managing large datasets.</p><h3><strong>Data Loading</strong></h3><p>The foundation step of any Power BI project is data loading. When dealing with large datasets, it’s crucial to decide the type of connection to be used. Here are some strategies and connection modes with their limitations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*QNayR1p6BPNbVT6sNPMkYA.png" /></figure><p>Consider using Direct Query or Live Connection when dealing with exceptionally large datasets. This allows you to keep the data in your source system and only fetch what you need when building reports.</p><h4><strong>✅Direct Query:</strong></h4><p>Direct Query allows you to build visualizations over very large datasets where importing all the data with pre-aggregation would be unfeasible.</p><p>Make sure to provide proper credentials for the power bi service to connect to the direct query source.</p><p>Also, there are limitations which comes along with using direct query.</p><p><strong>Among various limitations below are the notable ones:</strong></p><p>🔻With Direct Query, when you create or interact with a visualization, you must query the underlying source. The time that’s needed to refresh the visualization depends on the performance of the underlying data source.</p><p>🔻Direct Query mode doesn’t support date column drill down by year, quarter, month, or day.</p><p>🔻For table or matrix visualizations, there’s a 125-column limit for results that return more than 500 rows from Direct Query sources.</p><p>🔻 In the Direct Query mode, however, you will have limited measurement capabilities.</p><p>If you are working in a circumstance where you are unable to compromise the above-mentioned restrictions. select the import mode.</p><h4><strong>✅Live Connection:</strong></h4><p>A “Live connection” is a method in Power BI Desktop that allows you to construct a report without the need to create a dataset from scratch. When crafting your report using Power BI Desktop, you have the option to link it to an existing dataset.One thing to note is that Live Connection only connects to three types of data sources.</p><p>➡️ A dataset that already exists in Power BI service</p><p>️➡️ An Azure Analysis Services (AAS) database</p><p>➡️ An on-premises instance of SQL Server Analysis Services (SSAS)</p><p><em>Reference : </em><a href="https://learn.microsoft.com/en-us/power-bi/connect-data/service-live-connect-dq-datasets#live-connection"><em>Microsoft</em></a></p><h4><strong>Incremental Load:</strong></h4><p>Incremental load is a good option to consider in this scenario where you want to import large data using import mode although we won’t be focusing more on incremental load topic, below is the reference of the same.</p><p><em>Reference : </em><a href="https://learn.microsoft.com/en-us/power-bi/connect-data/incremental-refresh-overview"><em>Microsoft</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xv591lVJGDoeZvc-poBg0w.png" /><figcaption>source : Microsoft</figcaption></figure><p><strong>Query Folding</strong>: <em>Query folding</em> is the ability for a Power Query query to generate a single query statement to retrieve and transform source data.</p><p>The Power Query mashup engine strives to achieve query folding whenever possible for reasons of efficiency.</p><p>If you are working on a data source which doesn’t support query folding like Databricks, following the below approach would help u efficiently perform a full refresh on a large dataset.</p><h4>✅Import Mode :</h4><p>The most commonly employed mode for developing datasets is the “Import mode.” This approach offers swift performance through in-memory querying, providing modelers with design flexibility and supporting various features within the Power BI service.</p><p>When utilizing the import mode, developers may encounter an issue during the refresh of a sizable dataset, particularly one with an exceptionally high number of line items. This issue may manifest as a refresh failure or a refresh timeout error.</p><p>In this scenario, the following approaches can be tremendously beneficial.</p><h4><strong>Approach 1:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*EdaOwdSqftpAVLAwx7o-cA.png" /></figure><p>First thing you may try:</p><p>If you are a premium-licensed user of workspace, please follow these steps to enable the Large Dataset Storage feature:</p><blockquote>➡️Navigate to ‘Dataset.’</blockquote><blockquote>️️➡️Access ‘Settings.’</blockquote><blockquote>➡️Locate the ‘Large Dataset Storage Format’ option.</blockquote><blockquote>➡️Activate the toggle switch to turn on this feature.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*v9UMhqkwJ41I4fTKZ-zEwQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*z-FdXFd5uwD5kDS-W7rJYw.png" /></figure><p>This must significantly improve the dataset refresh performance by reducing the refresh duration.</p><h4><strong>Approach 2:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*YErDNr9k8cKh6LFqw5oECQ.png" /></figure><p>Review the data transformations applied to your dataset.</p><p>The presence of numerous Applied steps can significantly extend the time required to process the data with the desired transformations</p><p>For example If below is your case</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*o2-NZSxZXk1jy8TAQJJiPA.png" /></figure><p>Try writing all the transformation steps as a single query and modify the source query.</p><p><em>= #”1234567123456789 3 &lt;cloud-service-provider&gt;: sql/protocolv1/o/1234578923456789/0101–12&quot;(“&lt;column names &gt;”)</em></p><p>This will completely eliminate the need for data transformation time and enable the direct loading of transformed data at the source level, resulting in a noticeable improvement in the refresh time of the Power BI dataset.</p><h4><strong>Approach 3:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*4JMsL8z20pE3QJQCbVXp1Q.png" /></figure><p>These are the basic best practices which will optimize your dataset maintenance and report performance.</p><p><strong>Use Star Schema: </strong>Organize your data model using a star schema or a snowflake schema. This simplifies relationships and optimizes query performance.</p><p><strong>Aggregate Data:</strong> When possible, aggregate data at the source level to reduce the volume of data loaded into Power BI. This can significantly improve report responsiveness.</p><p><strong>Optimize Data Types: </strong>Use the appropriate data types for your columns to reduce memory usage. For example, use integers instead of decimals if precision isn’t critical.</p><p><strong>Filter Data Early: </strong>Apply filtering and data reduction steps as early as possible in your Power Query transformations to minimize the amount of data brought into the model.</p><p><strong>Remove Unnecessary Columns: </strong>Remove columns that are not needed for reporting to reduce data size and improve performance.</p><h3><strong>Conclusion</strong></h3><p>Handling large datasets in Power BI can be challenging, but by following these best practices for data modelling, loading, transformation, performance optimization, and ongoing maintenance, you can build datasets and reports that deliver insights efficiently and keep your users happy. Remember that each dataset is unique, so always monitor and adjust your approach based on the specific needs of your project.</p><p><em>If you found the above article useful, kindly consider giving it an applause and feel free to connect with me on these platforms:</em></p><p>Follow me on LinkedIn: <a href="https://www.linkedin.com/in/logesh-karthik-273862184/">Logesh Karthik</a></p><p>Follow me on Medium: <a href="https://medium.com/@s.logeshkarthik">https://medium.com/@s.logeshkarthik</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2354bde58125" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>