top of page
Writer's pictureAlan Campbell

Power BI & Business Central: Parameter Driven Date Filtering

Updated: Nov 21, 2023

In the dynamic world of data analytics, efficiency and precision are key. As a Power BI user, you're constantly navigating through vast oceans of data, seeking insights that can drive your business decisions. A common challenge is the need to filter transactional data, especially when dealing with comprehensive sources like the Business Central generalLedgerEntries table. This blog is your guide to mastering an essential technique: creating and implementing start and end date parameters for filtering this data.


Imagine you're preparing a financial report or analyzing transaction trends. You need specific data from a certain period - but how do you efficiently extract just that from the extensive generalLedgerEntries table? The answer lies in using the postingDate field effectively.


In this blog, we'll walk you through the steps of creating start and end date filters. These are not just any filters; they're custom-built parameters in the Power BI M Formula Language, tailored to streamline your data querying process. We'll start by setting up these parameters in Power BI, ensuring they're flexible and easy to adjust for future analyses.


Next, we'll delve into integrating these parameters within your Power BI queries, replacing rigid, hardcoded dates with dynamic selectors that adapt to your analytical needs. This approach not only enhances your data querying efficiency but also adds a layer of sophistication to your reporting capabilities.


Whether you're a seasoned Power BI user or new to the platform, this guide will provide you with valuable insights and practical steps to enhance your data analysis process. Let's dive in and unlock the full potential of your Business Central data with custom date filters!


Creating the Business Central Start and End Date Parameters


In this section we will create the start and end date parameters that we will use in the M Formula Language to filter the Business Cental generalLedgerEntries table during a query.


1.Click on Home in the upper menu and then click on Transform data to open the Power Query Editor in Power Bi.


click on the transform data button in the upper power bi menu to enter the Power Query Editor.
Transform Data in the Power BI Upper Menu

2. Click on Home in the upper menu and then New Parameter under Manage Parameters.


Click on New Parameter in the Power Query editor to create a new parameter
Create a New Parameter

3. Enter the following in the Manage Parameters pop-up window and then click the OK button. You can re-edit your parameter selection at any time in the future in Power Query.

a. Enter StartDateParameter in the Parameter Name.

b. Add a Description for the parameter.

c. Accept the default of Required.

d. Change the Type to Date.

e. Change the Suggested Values to Any value.

f. Enter the Current Value as your start date.


Enter the name of the startdateparameter when creating a new parameter in the power query editor of Power Bi
Create the StartDateParameter

4. Perform steps 2 and 3 once again. But, this time create a parameter called EndDateParameter. Exit the Power Query editor and save your work.


Fill out the Manage Parameters form to create the new enddateparameter in the power query editor of business central
Create the EndDateParameter

Referencing the Business Central Start and End Date Parameters


5. In the Report View click on the Data Pane on the left side of the screen and right-mouse on the Business Central generalLedgerEntries table.


Click on the edit query button to edit the business central generalledgerentries table in power query
Edit the Business Central generalLedgerEntries Table

6. Click on Custom Filter under Date Filters on the postingDate column.


click on custom date filter to create a date filter for the postingDate column in power bi
Create a Custom Date Filter for the postingDate Column

7. Enter the start and end date for filtering as shown below. You can enter any date range at this time as the dates we enter will be replaced by our new parameters in the next step.


set the start date and end date for the business central postingdate field in power bi
Filter postingDate Field

8. Click on the Advanced Editor in the Home tab.


click on the advanced editor in power query to edit the M formula language to edit the posting date filter
Advanced Editor in Power Query

9. Below is the M Formula Language that Power Bi created.

let
    Source = Dynamics365BusinessCentral.ApiContentsWithOptions(null, null, null, null),
    SANDBOX = Source{[Name="SANDBOX"]}[Data],
    #"CRONUS USA, Inc." = SANDBOX{[Name="CRONUS USA, Inc."]}[Data],
    v2.0 = #"CRONUS USA, Inc."{[Name="v2.0"]}[Data],
    generalLedgerEntries_table = v2.0{[Name="generalLedgerEntries",Signature="table"]}[Data],
    #"Filtered Rows" = Table.SelectRows(generalLedgerEntries_table, each [postingDate] >= #date(2022, 2, 1) and [postingDate] <= #date(2023, 11, 30))
in
    #"Filtered Rows"

Substitute the hardcoded date references for your new start and end date parameters as shown below. Close the editor and save your changes.

let
    Source = Dynamics365BusinessCentral.ApiContentsWithOptions(null, null, null, null),
    SANDBOX = Source{[Name="SANDBOX"]}[Data],
    #"CRONUS USA, Inc." = SANDBOX{[Name="CRONUS USA, Inc."]}[Data],
    v2.0 = #"CRONUS USA, Inc."{[Name="v2.0"]}[Data],
    generalLedgerEntries_table = v2.0{[Name="generalLedgerEntries",Signature="table"]}[Data],
    #"Filtered Rows" = Table.SelectRows(generalLedgerEntries_table, each [postingDate] >= StartDateParameter and [postingDate] <= EndDateParameter)
in
    #"Filtered Rows"

Conclusion


As we wrap up this journey through the nuanced process of creating and applying start and end date parameters in Power BI, it's clear that the intersection of precision and efficiency in data analysis is not just desirable but attainable. By following the steps outlined in this guide, you have equipped yourself with a powerful technique to filter the Business Central generalLedgerEntries table, transforming how you interact with and analyze your data.


The implementation of these parameters in the M Formula Language not only simplifies the process of sifting through extensive data sets but also provides a level of customization and flexibility that hardcoded date ranges cannot match. This ability to dynamically adjust date parameters enhances your data analysis, enabling more accurate and relevant insights.


Remember, the true power of these techniques lies in their application. Experiment with different date ranges, explore various scenarios, and see firsthand how these parameters can streamline your workflow and bolster your decision-making process.


We encourage you to continue exploring and mastering other features within Power BI. As you grow more proficient, you'll discover even more ways to optimize your data analytics practices, making your journey through the vast oceans of data not only manageable but also more insightful.


Thank you for joining us on this exploration of start and end date parameters in Power BI. We hope this guide has been a valuable addition to your analytical toolkit and that you feel more confident in navigating the complexities of Business Central data. Keep diving deeper, keep exploring, and most importantly, keep leveraging the power of data to drive impactful business decisions.

210 views0 comments

Kommentare


bottom of page