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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Mmaria
New Member

Set parameter = DateTime.LocalNow()

Hello! 

 

Is there any way to set a parameter as a function? I want to set a parameter as today like this: DateTime.LocalNow().

As a default I want it to be today's date but I also want to be able to set the date manually if I want to see data from a certain date in my dashboards.

 

Thank you!

 

9 REPLIES 9
DataSkills
Helper II
Helper II

I got this working using the code below. Note that I used data type Date for my version. 

let
Source = Date.From(DateTime.LocalNow())
meta [IsParameterQuery=true, Type=Date.Type, IsParameterQueryRequired=true]
in
Source
bengineer
New Member

Create your paramenter and then right click it on the right under your queries and select 'Advanced Editor'.  You can then put in a function.  In my case, I needed it as text so I used the following-

--------------------------------------

let
Source = let
Source1 = DateTime.ToText(DateTime.LocalNow())
in
Source1

meta [IsParameterQuery=true, Type="Text", IsParameterQueryRequired=true]
in
Source

But...with this the parameter is transformed into a query?

inna_sysco
Helper II
Helper II

Any updates on this topic?

franck_axires
Frequent Visitor

Hi you all M Gurus out there...

Has anyone managed to pass a DateTime.LocalNow() value as a parameter default ?

I'm trying it right now with the latest version of PBI Desktop but it seems the value is still interpreted as a String in the parameter editor.

Any clues ?

Best,

Franck

BhaveshPatel
Community Champion
Community Champion

That is currently not possible. Parameters only allow values with List of Values, Any Values or other Query as the suggested values. if you have only one value that is defined using DateTime.LocalNow() then you can use that value as a suggested values using Query Option in the parameters dialog box. However, You can use the list of values as the suggested values where you have to manually select the today's date to pass the parameter's value. It is not dynamic but with the parameters in the baby stage, it would be more convenient option.

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.
Anonymous
Not applicable

Want to revive this thread... is this still possible in the latest PowerBI version?

I'm trying to do this now as well. I think it must be possible

Trying to figure out the same issue... 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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