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
一棵黄葛树
Helper II
Helper II

Dynamic parameter in Power Query

Can a new parameter in Power Query be a dynamic date? Such as:
Dynamically return the last month-end date of the month in which today falls: = Date.AddDays(Date.StartOfMonth(DateTime.LocalNow()), -1))

1 ACCEPTED SOLUTION
v-pnaroju-msft
Community Support
Community Support

Hi 一棵黄葛树,

 

Thank you for the update. We sincerely apologise for the inconvenience caused.

 

Please find attached the PBIX file and a screenshot for your reference, which may assist in resolving the issue.

 

vpnarojumsft_0-1740993407986.png

 

If you find our response helpful, kindly mark it as the accepted solution and consider providing kudos. This will assist other community members facing similar queries.

 

Thank you.

View solution in original post

11 REPLIES 11
v-pnaroju-msft
Community Support
Community Support

Hi 一棵黄葛树,

 

Thank you for the update. We sincerely apologise for the inconvenience caused.

 

Please find attached the PBIX file and a screenshot for your reference, which may assist in resolving the issue.

 

vpnarojumsft_0-1740993407986.png

 

If you find our response helpful, kindly mark it as the accepted solution and consider providing kudos. This will assist other community members facing similar queries.

 

Thank you.

Thank you very much. Perfect has solved my problem and I feel the continuous attention and patient explanation. Previously, I misunderstood that it was creating a new step, not a new query.

v-pnaroju-msft
Community Support
Community Support

Hi 一棵黄葛树,

We have not received a response from you regarding the query and were following up to check if you have found a resolution. If you have identified a solution, we kindly request you to share it with the community, as it may be helpful to others facing a similar issue.

 

If you find the response helpful, please mark it as the accepted solution and provide kudos, as this will help other members with similar queries.

Thank you.

The problem still hasn't been resolved. Previously, AlienSX provided me with a solution, but I don't know how to operate it. Maybe because I don't have enough permissions, I can't upload attachments. Please ask him to help me take a look.

v-pnaroju-msft
Community Support
Community Support

Thank you, @AlienSx  and @Omid_Motamedise , for your response.

Hi 一棵黄葛树,

We sincerely appreciate your inquiry on the Microsoft Fabric Community Forum.

 

As per my understanding, if we intend to use the parameter, we cannot input code in the 'Current Value' field of the Manage Parameters screen; instead, we must enter the date.

As an alternative, if we wish to use the code, we need to define the parameter separately in the Advanced Editor and then reference it accordingly. Kindly refer to the attached sample code and images provided below:

let
Source = Csv.Document(File.Contents("C:\Users\v-pnaroju\Downloads\sampledata.csv"),[Delimiter=",", Columns=2, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type datetime}, {"Sales", Int64.Type}}),
MyParam=Date.AddDays(Date.StartOfMonth(DateTime.LocalNow()), -1),
FilterRows=Table.SelectRows(#"Changed Type",each [Date]<MyParam)
in
FilterRows

vpnarojumsft_0-1740494026589.png

vpnarojumsft_1-1740494092931.png

Additionally, please find below the reference links for your convenience:
Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Learn
Parameters - Power Query | Microsoft Learn

If you find our response helpful, we kindly request you to mark it as the accepted solution and provide kudos. This will assist other community members encountering similar queries.

 

Thank you.

Omid_Motamedise
Super User
Super User

Yes, 
see the following:

let
Today = DateTime.LocalNow(),
StartOfCurrentMonth = Date.StartOfMonth(Today),
LastMonthEnd = Date.AddDays(StartOfCurrentMonth, -1)
in
LastMonthEnd


If my answer helped solve your issue, please consider marking it as the accepted solution.

Thanks, the new query is fine, my need is for new parameters. Or how to set the dynamic date in the parameter?

AlienSx
Super User
Super User

Date.AddDays(Date.StartOfMonth(DateTime.LocalNow()), -1) meta [IsParameterQuery=true, IsParameterQueryRequired=true]

Thanks for the answer, but I don't know where to add this meta, could you make a PBIX attachment for me, much appreciated!

create blank query and paste this code over there

Thanks for replying again, maybe I wasn't clear before.
I was hoping to create a new parameter in Power Query (dynamically display a date, e.g. if today is 2025/2/21, then the date at the end of the last month will be: 2025/1/31), and then use to call that parameter in other queries.
Such as table table, filter 20251/1/31 before all rows of data. 

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