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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
ejhh12
Regular Visitor

Create a Query Parameter which is the last day in the current month

I have a JSON query which loads data into my report. Instead of hard coding a date I want a dynamic value. I have managed to get to the point where my json URL contains: &startDate=2020-01-01&endDate=" & Parameter1 & "& where Parameter1 is a text parameter I've typed out '2020-12-01' but I would like to replace this with something like:

 

Date.EndOfMonth(date.utcnow,0) so if the date today is 5th June 2020, it returns 30th June 2020 in the format 2020-06-30, once we get to say 2nd July 2020, it returns 31st July 2020 in the format 2020-07-31.

 

Thanks.

 

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

This M expression will get you the end of the current month in the format you need for the web call.

 

let
Source = Date.EndOfMonth(Date.From(DateTime.LocalNow())),
#"Converted to Table" = #table(1, {{Source}}),
#"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Today", each Text.AfterDelimiter([Column1],"/",1) & "-" & Text.PadStart(Text.BeforeDelimiter([Column1],"/", 0), 2,"0") & "-" & Text.PadStart(Text.BetweenDelimiters([Column1],"/","/"),2, "0"), type text)

in
#"Added Custom"

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


ibarrau
Super User
Super User

Hi, I'm not sure if you just need the following code or something else.

= Date.EndOfMonth(DateTime.LocalNow())

Let me know if this is ok for you 🙂

 

Regards, 


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

Happy to help!

LaDataWeb Blog

Hi, That gets me very close but I get the following error when I pass that information into my json request: Expression.Error: We cannot apply operator & to types Text and DateTime. Details: Operator=& Left=[*removed URL for privacy*]&startDate=2020-01-01&endDate= Right=01/07/2020 00:00:00 My URL preview looks like [*removed URL for privacy*]&startDate=2020-01-01&endDate={}&lastFlag=false I think this is something to do with the data type, PowerBI now showing a calendar next to Parameter2 (just a test using your Date.EndOfMonth(DateTime.LocalNow()) ) rather than the parameter icon.... How can I convert 2020-06-30T23:59:59.9999999 to just 2020-06-30 as a string?

Hi. You can change it like this:

= Date.ToText(Date.EndOfMonth(DateTime.Date(DateTime.LocalNow())), "yyyy-MM-dd")

Hope this helps,

Regards, 


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

Happy to help!

LaDataWeb Blog

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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