Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
rmcgrath
Advocate II
Advocate II

Dynamic start and end dates?

Hello - I used the "Download with Live Connection" option to get the data from a Power BI Report into Excel.  The code below is the code for this Live Connection.  Since it is a Connection and not a Query, is there a way to modify this code so that the Start Date and End Date would be connected to cells (one for Start Date and the other for End Date) in the Excel file first and then go grab the Power BI Report data (upon Refresh)?

 

DEFINE

               VAR __DS0FilterTable =

                              TREATAS({"'Date Dim'[Fiscal Month Year]"}, 'Parameter - Time'[Parameter - Time Fields])

 

               VAR __DS0FilterTable2 =

                              TREATAS(

                                             {"'Dimension Sets Pivot'[Dimension Set 4]",

                                                            "'Dimension Sets Pivot'[Dimension Set 7]"},

                                             'Parameter - Dimension Sets'[Dimension Sets Fields]

                              )

 

               VAR __DS0FilterTable3 =

                              TREATAS(

                                             {"'Measure'[GL Amount]",

                                                            "'Measure'[Debit Amount]",

                                                            "'Measure'[Credit Amount]"},

                                             'Parameter - Values'[Parameter - Values Fields]

                              )

 

               VAR __DS0FilterTable4 =

                              TREATAS(

                                             {"'General Ledger Accounts'[Account Category]",

                                                            "'General Ledger Accounts'[Custom Accounting Subcategory]",

                                                            "'General Ledger Accounts'[Company Name]",

                                                            "'General Ledger Accounts'[Custom Accounting Totals]",

                                                            "'General Ledger Accounts'[Custom Accounting Category]",

                                                            "'General Ledger Accounts'[Account Subcategory Descript]",

                                                            "'General Ledger Accounts'[Name]",

                                                            "'General Ledger Accounts'[Number]"},

                                             'Parameters - Account '[Parameters - Account  Fields]

                              )

 

               VAR __DS0FilterTable5 =

                              FILTER(

                                             KEEPFILTERS(VALUES('Date Dim'[FiscalBaseDate])),

                                             AND(

                                                            'Date Dim'[FiscalBaseDate] >= DATE(2024, 1, 1),

                                                            'Date Dim'[FiscalBaseDate] < DATE(2024, 2, 15)

                                             )

                              )

 

               VAR __DS0FilterTable6 =

                              TREATAS({TRUE}, 'Date Dim'[Is Past])

 

               VAR __DS0Core =

                              SUMMARIZECOLUMNS(

                                             'General Ledger Accounts'[Account Category],

                                             'General Ledger Accounts'[Category Sort Order],

                                             'General Ledger Accounts'[Custom Accounting Subcategory],

                                             'Date Dim'[Fiscal Month Year],

                                             'Date Dim'[Month Offset],

                                             'General Ledger Accounts'[Company Name],

                                             'General Ledger Accounts'[Custom Accounting Totals],

                                             'General Ledger Accounts'[Custom Accounting Category],

                                             'General Ledger Accounts'[Custom Acc. Category Sort],

                                             'General Ledger Accounts'[Account Subcategory Descript],

                                             'Dimension Sets Pivot'[Dimension Set 4],

                                             'Dimension Sets Pivot'[Dimension Set 7],

                                             'General Ledger Accounts'[Name],

                                             'General Ledger Accounts'[Number],

                                             __DS0FilterTable,

                                             __DS0FilterTable2,

                                             __DS0FilterTable3,

                                             __DS0FilterTable4,

                                             __DS0FilterTable5,

                                             __DS0FilterTable6,

                                             "GL_Amount", 'Measure'[GL Amount],

                                             "Debit_Amount", 'Measure'[Debit Amount],

                                             "Credit_Amount", 'Measure'[Credit Amount]

                              )

 

               VAR __DS0BodyLimited =

                              TOPN(

                                             500000,

                                             __DS0Core,

                                             'General Ledger Accounts'[Category Sort Order],

                                             1,

                                             'General Ledger Accounts'[Account Category],

                                             1,

                                             'General Ledger Accounts'[Custom Accounting Subcategory],

                                             1,

                                             'Date Dim'[Month Offset],

                                             1,

                                             'Date Dim'[Fiscal Month Year],

                                             1,

                                             'General Ledger Accounts'[Company Name],

                                             1,

                                             'General Ledger Accounts'[Custom Accounting Totals],

                                             1,

                                             'General Ledger Accounts'[Custom Acc. Category Sort],

                                             1,

                                             'General Ledger Accounts'[Custom Accounting Category],

                                             1,

                                             'General Ledger Accounts'[Account Subcategory Descript],

                                             1,

                                             'Dimension Sets Pivot'[Dimension Set 4],

                                             1,

                                             'Dimension Sets Pivot'[Dimension Set 7],

                                             1,

                                             'General Ledger Accounts'[Name],

                                             1,

                                             'General Ledger Accounts'[Number],

                                             1

                              )

 

EVALUATE

               __DS0BodyLimited

 

ORDER BY

               'General Ledger Accounts'[Category Sort Order],

               'General Ledger Accounts'[Account Category],

               'General Ledger Accounts'[Custom Accounting Subcategory],

               'Date Dim'[Month Offset],

               'Date Dim'[Fiscal Month Year],

               'General Ledger Accounts'[Company Name],

               'General Ledger Accounts'[Custom Accounting Totals],

               'General Ledger Accounts'[Custom Acc. Category Sort],

               'General Ledger Accounts'[Custom Accounting Category],

               'General Ledger Accounts'[Account Subcategory Descript],

               'Dimension Sets Pivot'[Dimension Set 4],

               'Dimension Sets Pivot'[Dimension Set 7],

               'General Ledger Accounts'[Name],

               'General Ledger Accounts'[Number]

1 ACCEPTED SOLUTION
GilbertQ
Super User
Super User

Hi @rmcgrath 

 

Could I ask you a question? And what are you trying to achieve by extracting all of your financial information into excel? Is this for data extract or is this to do some further analysis? 1 way you could do the dynamic date is by using the Timeline Slicer in Excel. Which had been limit the range of dates?

 

Also have a look at this: Consuming a DAX query in Excel – Unplugged #5 - SQLBI





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

View solution in original post

1 REPLY 1
GilbertQ
Super User
Super User

Hi @rmcgrath 

 

Could I ask you a question? And what are you trying to achieve by extracting all of your financial information into excel? Is this for data extract or is this to do some further analysis? 1 way you could do the dynamic date is by using the Timeline Slicer in Excel. Which had been limit the range of dates?

 

Also have a look at this: Consuming a DAX query in Excel – Unplugged #5 - SQLBI





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.