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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Falcon
Helper I
Helper I

Advance Query - load data from the latest date to current date

Hello all,

 

I am trying to load data using API which requires parameters "startDateTime" and "endDateTime" in the request URL. The data table has a date column. My plan is as follows.

  • Run a first query to pull data in a certain time range.
  • Run the second query (daily) pulling data from the same data source. The "startDateTime" will be the "latest date" from the first table +1, and "endDateTime" will be the current date (which I assign a variable to DateTime.LocalNow().

I am struggling to create a variable "LatestDate" which should be the latest date from the first table. Can anyone help me with this issue? 

 

Thanks in advance

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Falcon ,

@lbendlin Thanks for your concern about this case!

For "startDateTime", to extract the Maximum Date from Your Table, you can use the following M code to create a new query:

let
    Source = YourTableName,
    MaxDate = Table.Max(Source, "YourDateColumnName")[YourDateColumnName]
in
    MaxDate

For the "endDateTime", you can directly use

DateTime.LocalNow()

in your API request URL or format it as needed.

Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @Falcon ,

@lbendlin Thanks for your concern about this case!

For "startDateTime", to extract the Maximum Date from Your Table, you can use the following M code to create a new query:

let
    Source = YourTableName,
    MaxDate = Table.Max(Source, "YourDateColumnName")[YourDateColumnName]
in
    MaxDate

For the "endDateTime", you can directly use

DateTime.LocalNow()

in your API request URL or format it as needed.

Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks a lot. That worked for me.

lbendlin
Super User
Super User

are you familiar with the concept of self referencing semantic models?  That might actually be appropriate for your use case.

Hello lbendlin,

 

Sorry I am not familiar with the concept of self referencing semantic model. Can you explain further? 

 

Thanks for all the help

in your Power Query code you can access a SSAS data source, via a DAX query. That includes the semantic model you are sitting in...  So you can theoretically run a DAX query to ask for the max date in the semantic model, and then add all the data points after that date through your API. 

 

It's brain freeze territory,  so maybe having  csv files with the extracts is easier.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors