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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

Dynamic M query parameters in Power BI Desktop

Dynamic M Parameters is not working.we have followed the below process:

1.  We have created a Date parameter

Rohini_dubey_0-1650620868644.png

2. We have imported a table using SQL query where date variable is declared as 12/04/2022.

 

Rohini_dubey_1-1650621267738.png

3. Now, In Advanced Editor we are changing the code to get the payment created date as per the declare date variable.

let

 

Filterquery = "SELECT#(lf)SP.[PaymentRef]#(lf), SP.[ReportingType]#(lf), SP.[PaymentMethod]#(lf), SP.[PaymentCreatedDate]#(lf), SP.[BillAllocationStatus]#(lf), SP.[BillAmountUnallocated]#(lf), 'Allocated In' as [Status]#(lf)FROM [DW].[F_Drv_Suspense_Payments] SP#(lf) where SP.[PaymentCreatedDate] = " & DateTime.ToText (P_Date, "yyyy-mm-dd"),

 

Source = Sql.Database("wtr-uks-tst-datafactorydb.database.windows.net", "WTR-UKS-TEST-DWHDB", [Query="SELECT#(lf)SP.[PaymentRef]#(lf), SP.[ReportingType]#(lf), SP.[PaymentMethod]#(lf), SP.[PaymentCreatedDate]#(lf), SP.[BillAllocationStatus]#(lf), SP.[BillAmountUnallocated]#(lf), 'Allocated In' as [Status]#(lf)FROM [DW].[F_Drv_Suspense_Payments] SP#(lf)"])

 

in
Source


As per the above process; The Payment created date supposed to filtered as per the declared Date parameter which is "12/04/2022".


Conclusion; We want to create a "Dynamic date parameter" so that user should be able to change the date by itself to filter the data.


 

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

Hi @Anonymous ,

You can update your M query codes as below in Advanced Editor, the part with red font is updated ones...

let
Source = Sql.Database("wtr-uks-tst-datafactorydb.database.windows.net", "WTR-UKS-TEST-DWHDB",
[Query="SELECT#(lf)SP.[PaymentRef]#(lf), SP.[ReportingType]#(lf), SP.[PaymentMethod]#(lf), SP.[PaymentCreatedDate]#(lf), SP.[BillAllocationStatus]#(lf), SP.[BillAmountUnallocated]#(lf), 'Allocated In' as [Status]#(lf)
FROM [DW].[F_Drv_Suspense_Payments] SP#(lf) where format(SP.[PaymentCreatedDate],'M/d/yyyy') = '"&Date.ToText(P_Date)&"' "])
in
Source

Power BI Introduction: Working with SQL Server data in Power BI Desktop

Power BI Desktop Query Parameters

Best Regards

Community Support Team _ Rena
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

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

You can update your M query codes as below in Advanced Editor, the part with red font is updated ones...

let
Source = Sql.Database("wtr-uks-tst-datafactorydb.database.windows.net", "WTR-UKS-TEST-DWHDB",
[Query="SELECT#(lf)SP.[PaymentRef]#(lf), SP.[ReportingType]#(lf), SP.[PaymentMethod]#(lf), SP.[PaymentCreatedDate]#(lf), SP.[BillAllocationStatus]#(lf), SP.[BillAmountUnallocated]#(lf), 'Allocated In' as [Status]#(lf)
FROM [DW].[F_Drv_Suspense_Payments] SP#(lf) where format(SP.[PaymentCreatedDate],'M/d/yyyy') = '"&Date.ToText(P_Date)&"' "])
in
Source

Power BI Introduction: Working with SQL Server data in Power BI Desktop

Power BI Desktop Query Parameters

Best Regards

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors