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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Changing Date Range to yesterday in Advanced query editor?

I am trying to change the date range for my query to have a dynamic end date (yesterday) where the query will pull in data up until sysdate()-1 (SQL syntax) when it is refreshed. How would i do this in DAX? In the code below I would like to change the #daterange to {#date(2019, 2, 10), #sys.date()-1}

{
            {Cube.ApplyParameter, "DateRange", {#date(2019, 2, 10), #date(2019, 5, 29)},
            {Cube.ApplyParameter, "Segment", {{"s300001442_56f2fd0ce4b0087c7199b66e"}}},
            {Cube.AddAndExpandDimensionColumn, "DateGranularity", {"year", "month", "day"}, {"Date Granularity.Level 1: Year", "Date Granularity.Level 2: Month", "Date Granularity.Level 3: Day"}},
            {Cube.AddAndExpandDimensionColumn, "prop10", {"prop10"}, {"10. Properties"}},
            {Cube.AddMeasureColumn, "Page Views", "pageviews"},
            {Cube.AddMeasureColumn, "Unique Visitors", "uniquevisitors"},
            {Cube.AddMeasureColumn, "Visits", "visits"}
        })
1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

If I understand your requirement correctly that you want to get data based on the date range (2019-2-10, today-1) in power bi?

However, I still have a little confused about how do you want to achieve that? DAX or Power Query in Advanced Editor?

For Power quey, we could use Date.AddDays(DateTime.FixedLocalNow(), -1) to get the yesterday date.

For DAX, we could use DATEADD(DateTime[DateKey],-1,day) to calculate the last day data.

In addition, we could use relative date slicer to filter the data for last 1 day.

If you still need help, feel free to ask.

Best  Regards,

Cherry

 

 

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

4 REPLIES 4
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

If I understand your requirement correctly that you want to get data based on the date range (2019-2-10, today-1) in power bi?

However, I still have a little confused about how do you want to achieve that? DAX or Power Query in Advanced Editor?

For Power quey, we could use Date.AddDays(DateTime.FixedLocalNow(), -1) to get the yesterday date.

For DAX, we could use DATEADD(DateTime[DateKey],-1,day) to calculate the last day data.

In addition, we could use relative date slicer to filter the data for last 1 day.

If you still need help, feel free to ask.

Best  Regards,

Cherry

 

 

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

Hi Cherry

 

I would like to know how you would add the above query in the advanced editor. I am looking for exactly the same solution.
Here is my date range in Advanced editor: How would I replace the last part of my query and switch with yours Date.AddDays(DateTime.FixedLocalNow(), -1) t

{Cube.ApplyParameter, "DateRange", {#date(2022, 6, 20), #date(2022, 6, 26)}},     <--I would like to replace this part ,#date(2022,6,26)  to yesterday date.  
So every day the end date would automatically change from 26 june to 27 to 28 june, and so on.
Can you please help me with the above code. 

mr_a
Frequent Visitor

actually I found the solution. I replaced the end date  #date(2022,6,26) with this code 

Date.AddDays(DateTime.Date(DateTime.LocalNow()), -1)



Anonymous
Not applicable

I was looking for how to do it in Power Query. This worked, thank you!

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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