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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
sonya7
Helper III
Helper III

Creating a dynamic date parameter with m query in Power BI

Hello everyone, the user must select the start and end date from two separate date tables. I created parameters for these. However, I want to limit my end date to 90 days from the selected start date. Although I think I used the appropriate query for this, I realize that it does not work according to the start date I selected from the slicer on the frontend. How and in what way can I do this?

 

note: this date slicer seems very difficult, it is very difficult to go down the list, I can take your suggestion for a different way

 

start date = 

sonya7_0-1721978415012.png

finish date = 

sonya7_1-1721978450376.png

 

parameters = 

sonya7_2-1721978477011.pngsonya7_3-1721978484461.pngsonya7_4-1721978513000.png

sonya7_0-1721979365583.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @sonya7 

You can refer to the following solution.

1.I create a paramater and set its type to Text, then input the currentvalue, such as'20240530โ€˜

vxinruzhumsft_0-1722230305774.png

2.In advanced Editor , change the code to the following.

let

    Source = Sql.Database("xxx", "xxx", [Query="
     select * from xxx where [Date]>= ' " & Parameter1 & "' and [Date]<=DATEADD(DAY, 90, ' " & Parameter1 & "')  "])
in
    Source

Then close and apply it, in power desktop, create the following calendar table.

Calendar = ADDCOLUMNS(CALENDAR(DATE(2024,5,1),TODAY()),"Format",FORMAT([Date],"YYYYMMDD"))

Then click the Format column and bind it to the paramater.

vxinruzhumsft_1-1722230701362.png

Then put the format column to the slicer, it can work.

vxinruzhumsft_2-1722230740404.png

 

Best Regards!

Yolo Zhu

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
Anonymous
Not applicable

Hi @sonya7 

You can refer to the following solution.

1.I create a paramater and set its type to Text, then input the currentvalue, such as'20240530โ€˜

vxinruzhumsft_0-1722230305774.png

2.In advanced Editor , change the code to the following.

let

    Source = Sql.Database("xxx", "xxx", [Query="
     select * from xxx where [Date]>= ' " & Parameter1 & "' and [Date]<=DATEADD(DAY, 90, ' " & Parameter1 & "')  "])
in
    Source

Then close and apply it, in power desktop, create the following calendar table.

Calendar = ADDCOLUMNS(CALENDAR(DATE(2024,5,1),TODAY()),"Format",FORMAT([Date],"YYYYMMDD"))

Then click the Format column and bind it to the paramater.

vxinruzhumsft_1-1722230701362.png

Then put the format column to the slicer, it can work.

vxinruzhumsft_2-1722230740404.png

 

Best Regards!

Yolo Zhu

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

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.