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
praveenk
Frequent Visitor

How to filter data for rolling 24 months using SAP BW BEx Query

Hello Everyone,

 

I have to pass two required parameters StartDate and EndDate at the BEx query level.  If I pass Start Date as "20220101" and EndDate as "20220131", these values are fixed in the parameters section. What I'm looking at here is how can I achieve a rolling 24 months of data based on the current date when data flow is refreshed daily. What changes do I have to make in the advanced editor for making this query to bring back rolling 24 months of data from the source system?

 

For Example: If the data flow is refreshed today (08/23/2022), It has to bring all the data from 08/23/2020 - 08/23/2022.

 

Any suggestions are much appreciated.

 

praveenk_0-1661310751303.png

4 REPLIES 4
praveenk
Frequent Visitor

 
I didn't actually get what you are trying to say. Below is my code, where do you want me to change it?
 
 
let
  Source = SapBusinessWarehouse.Cubes("XXX.XXX.", "11", "800", [Implementation = "2.0"]),
  #"Navigation 1" = Source{[Name = "ZCP_BLUE_Q"]}[Data],
  Shipping_Logistics_Blue_Box = #"Navigation 1"{[Id = "ZCP_BLUE_Q/ZCP_BLUEBOX_LOGISTICS_Q001"]}[Data],
  StartDate = Date.AddMonths(DateTime,Date(DateTime.FixedLocalNow()),-24),
  EndDate = DateTime.Date(DateTime,FixedLocalNow()),
  #"Added items" = Cube.Transform(Shipping_Logistics_Blue_Box, {{Cube.ApplyParameter, "[!V000001]", {"20220101", "20220131"}}, {Cube.AddMeasureColumn, "Actual Delivery Qty", "[Measures].[00O2TH886DUSLQ0ERABGKVORJ]"}, {Cube.AddMeasureColumn, "Delivery Quantity", "[Measures].[00O2TH886DUSLQ0ERABGKWE1R]"}, {Cube.AddAndExpandDimensionColumn, "[0COSTELMNT]", {"[0COSTELMNT].[LEVEL01]"}, {"Cost Element Level 01"}}, {Cube.AddAndExpandDimensionColumn, "[HPPTASTRD]", {"[HPPTASTRD].[LEVEL01]"}, {"Transaction Date Level 01"}}})
in
  #"Added items"
amitchandak
Super User
Super User

@praveenk , Use these two dates

 

Let

  StartDate =Date.AddMonths(DateTime.Date( DateTime.FixedLocalNow()),-24),

  EndDate= DateTime.Date( DateTime.FixedLocalNow()) ,

<Use these two in you code now>

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

@amitchandak 

 

I don't see the data beyond the parameter's value after adding those two lines to the code. Do I have to remove the date values and substitute them with the StartDate and EndDate?

 

praveenk_0-1661312170174.png

 

 

 

@praveenk , Those two date values you try to use these parameters

 

if needed convert to text

 

Date.ToText([StartDate],"yyyyMMdd")

 

replace 20220101 and the other date and check if it works

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

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.