Forum Discussion
Creating a dynamic date parameter with m query in Power BI
- Anonymous2 years ago
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‘
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 SourceThen 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.
Then put the format column to the slicer, it can work.
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.
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‘
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.
Then put the format column to the slicer, it can work.
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.