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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
KamilGH
Frequent Visitor

Dynamic M query parameter for Start & End Date

Hi,

I want to use M parameters and slicers to allow users to select start and end dates to filter the result of the report.

I created two DateTime parameters "StartDate" and "EndDate" and passed them into the advanced editor using DateTime.ToText in two different ways as the following:

 

Method 01:

 

 

let
Source = Sql.Database("**.***.**.***", "******", [Query="SELECT MEMBERSHIP_ID, BEG_DATESTAMP #(lf)FROM MEMBERSHIP_HISTORY#(lf)WHERE BEG_DATESTAMP >= '"& DateTime.ToText(StartDate,"MM-dd-yyyy") &"'#(lf)AND BEG_DATESTAMP <= '"& DateTime.ToText(EndDate,"MM-dd-yyyy") &"'"])
in
Source

 

Method 02:

 

 

let
Source = Sql.Database("**.***.**.***", "******", [Query="SELECT * #(lf)FROM MEMBERSHIP_HISTORY#(lf)WHERE BEG_DATESTAMP >= '"& DateTime.ToText(StartDate,"MM-dd-yyyy") &"'#(lf)AND BEG_DATESTAMP <= '"& DateTime.ToText(EndDate,"MM-dd-yyyy") &"'"])
in
Source

 

Both methods are updating the query based on the dates I enter in the parameters.

 

Then, I created two calendar tables for "Start Date" and "End Date" using the following syntax and bound them to the parameters.

Start Date = CALENDAR(DATE(2019,01,01),TODAY())
End Date = CALENDAR(DATE(2019,01,01),TODAY())
 
The issue I'm having is that when I create slicers using the date tables and select one of the dates, the data in the other visual disappear and I get the error message in the screenshots below
 
KamilGH_1-1667244243278.png

 

 
KamilGH_0-1667244096318.png

 

Does anyone know where I made mistakes?

 

Thanks in advance.

 

1 ACCEPTED SOLUTION
KamilGH
Frequent Visitor

Hi everyone,

 

an update.

I upgraded the Power Bi to the latest version and the issue is solved.

 

Thanks,

 

Kamil

View solution in original post

5 REPLIES 5
KamilGH
Frequent Visitor

Hi everyone,

 

an update.

I upgraded the Power Bi to the latest version and the issue is solved.

 

Thanks,

 

Kamil

Anonymous
Not applicable

Hi @KamilGH ,

Thanks for your feedback and sharing the solution here. Could you please mark your post as Answered since the problem has been resolved? Thank you.

Best Regards

Thennarasu_R
Responsive Resident
Responsive Resident

Try this  manage paraneters in Querry Editor

Thanks,
Thennarasu R

amitchandak
Super User
Super User

@KamilGH , has StartDate some default value. 

 

Also, can you click on Copy details on clipboard and share that

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak 

thanks for responding.

 

the parameters StartDate and EndDate are have "current Value"

KamilGH_0-1667316873374.png

Below are the details of the error message I'm getting:

Feedback Type:
Frown (Error)

Timestamp:
2022-11-01T15:35:10.6783826Z

Local Time:
2022-11-01T11:35:10.6783826-04:00

Release:
July 2021

Product Version:
2.95.983.0 (21.07) (x64)

Error Message:
Query (2, 14) The M parameter 'StartDate' not defined in model or M parameter type is not valid.

Workbook Package Info:
1* - en-US, Query Groups: 0, fastCombine: Disabled, runBackgroundAnalysis: True.

Telemetry Enabled:
True

Snapshot Trace Logs:
C:\Users\*****\AppData\Local\Microsoft\Power BI Desktop\FrownSnapShot519e8ee3-ff05-42bf-b065-9c8d1dbf0fd2.zip

Model Default Mode:
Composite

Model Version:
PowerBI_V3

Performance Trace Logs:
C:\Users\******\AppData\Local\Microsoft\Power BI Desktop\PerformanceTraces.zip

Enabled Preview Features:
PBI_JsonTableInference
PBI_NewWebTableInference
PBI_ImportTextByExample
PBI_ExcelTableInference
PBI_dynamicParameters
PBI_rdlNativeVisual

Disabled Preview Features:
PBI_shapeMapVisualEnabled
PBI_SpanishLinguisticsEnabled
PBI_qnaLiveConnect
PBI_azureMapVisual
PBI_dataPointLassoSelect
PBI_compositeModelsOverAS
PBI_enhancedTooltips
PBI_enableWebView2

Disabled DirectQuery Options:
TreatHanaAsRelationalSource

Cloud:
GlobalCloud

DPI Scale:
100%

Supported Services:
Power BI

Formulas:


section Section1;

shared StartDate = #datetime(2022, 9, 1, 0, 0, 0) meta [IsParameterQuery=true, Type="DateTime", IsParameterQueryRequired=true];

shared EndDate = #datetime(2022, 9, 30, 0, 0, 0) meta [IsParameterQuery=true, Type="DateTime", IsParameterQueryRequired=true];

shared #"Simple (ToText)" = let
Source = Sql.Database("*******", "*****", [Query="SELECT MEMBERSHIP_ID, BEG_DATESTAMP #(lf)FROM MEMBERSHIP_HISTORY#(lf)WHERE BEG_DATESTAMP >= '"& DateTime.ToText(StartDate,"MM-dd-yyyy") &"'#(lf)AND BEG_DATESTAMP <= '"& DateTime.ToText(EndDate,"MM-dd-yyyy") &"'"])
in
Source;

shared #"Simple (filterquery)" = let
filterquery="SELECT MEMBERSHIP_ID, BEG_DATESTAMP #(lf)FROM MEMBERSHIP_HISTORY#(lf)WHERE BEG_DATESTAMP >= '"& DateTime.ToText(StartDate,"yyyy-MM-dd") &"'#(lf)AND BEG_DATESTAMP <= '"& DateTime.ToText(EndDate,"yyyy-MM-dd") &"'",
Source = Sql.Database("*****", "*******", [Query=filterquery])
in
Source;

Thanks,

 

Kamil

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors