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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
RSD
Helper II
Helper II

Sum Within Window

Hi There,

Could you please help me with below issue in power bi?

 

As Shown in Below Image, I need help help in ("Shipment Within event window") Column

In Current scenario , We are Forming Event window as an when we find nonnblank value for 'Forecat Unit' .(Tag=1).We are Creating Event window for 2 Consecutive weeks and taking sum of Shipment QTY. E,g For Forecast Unit = 700 then Shipment Within event window =229+222+79=530.

 

BUt I need to get rid of Overlapping window issue. e.g For Forecast Unit = 250 then Shipment Within event window=171,I need to ignore 71 because it has been covered in above window.

 

Formula:

Shipment within event window =

             CALCULATE(SUM('Forecast Code'[Shipment QTY]),DATESBETWEEN('Forecast Code'[Master Date],FIRSTDATE('Forecast Code'[Master Date]),

            FIRSTDATE('Forecast Code'[Master Date])+14),ALLEXCEPT('Forecast Code','Forecast Code'[Customer],'Forecast Code'[Master Date],'Forecast Code'[BC]))

 

Event Window Issue.PNG

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

hi  @RSD 

For your case, try this logic:

Step1:

Add a rank column for Master Date for each BC&Customer.

rank = RANKX(FILTER('Forecast Code','Forecast Code'[BC]=EARLIER('Forecast Code'[BC])&&'Forecast Code'[Customer]=EARLIER('Forecast Code'[Customer])),[Master Date],,ASC)

Step2:

then use this logic to get the column

Result = 
var _rankfortag1=IF('Forecast Code'[Tag]=1,RANKX(FILTER('Forecast Code','Forecast Code'[BC]=EARLIER('Forecast Code'[BC])&&'Forecast Code'[Customer]=EARLIER('Forecast Code'[Customer])&&'Forecast Code'[Tag]=1),[Master Date],,ASC))
var _rank=IF('Forecast Code'[Tag]=1,RANKX(FILTER('Forecast Code','Forecast Code'[BC]=EARLIER('Forecast Code'[BC])&&'Forecast Code'[Customer]=EARLIER('Forecast Code'[Customer])),[Master Date],,ASC)) 
var _nextrank=CALCULATE(MIN('Forecast Code'[rank]),FILTER(ALLEXCEPT('Forecast Code','Forecast Code'[BC],'Forecast Code'[Customer]),'Forecast Code'[rank]>EARLIER('Forecast Code'[rank])&&'Forecast Code'[Tag]=1)) return
IF(_rankfortag1=1,CALCULATE(SUM('Forecast Code'[Shipment QTY]),FILTER(ALLEXCEPT('Forecast Code','Forecast Code'[BC],'Forecast Code'[Customer]),'Forecast Code'[rank]>=_rank&&'Forecast Code'[rank]<=_nextrank)),IF(_rankfortag1>1,CALCULATE(SUM('Forecast Code'[Shipment QTY]),FILTER(ALLEXCEPT('Forecast Code','Forecast Code'[BC],'Forecast Code'[Customer]),'Forecast Code'[rank]>_rank&&'Forecast Code'[rank]<=_nextrank)
)))

Result:

1.JPG

 

here is sample pbix file, please try it.

 

Regards,

Lin

 

 

Community Support Team _ Lin
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-lili6-msft
Community Support
Community Support

hi  @RSD 

For your case, try this logic:

Step1:

Add a rank column for Master Date for each BC&Customer.

rank = RANKX(FILTER('Forecast Code','Forecast Code'[BC]=EARLIER('Forecast Code'[BC])&&'Forecast Code'[Customer]=EARLIER('Forecast Code'[Customer])),[Master Date],,ASC)

Step2:

then use this logic to get the column

Result = 
var _rankfortag1=IF('Forecast Code'[Tag]=1,RANKX(FILTER('Forecast Code','Forecast Code'[BC]=EARLIER('Forecast Code'[BC])&&'Forecast Code'[Customer]=EARLIER('Forecast Code'[Customer])&&'Forecast Code'[Tag]=1),[Master Date],,ASC))
var _rank=IF('Forecast Code'[Tag]=1,RANKX(FILTER('Forecast Code','Forecast Code'[BC]=EARLIER('Forecast Code'[BC])&&'Forecast Code'[Customer]=EARLIER('Forecast Code'[Customer])),[Master Date],,ASC)) 
var _nextrank=CALCULATE(MIN('Forecast Code'[rank]),FILTER(ALLEXCEPT('Forecast Code','Forecast Code'[BC],'Forecast Code'[Customer]),'Forecast Code'[rank]>EARLIER('Forecast Code'[rank])&&'Forecast Code'[Tag]=1)) return
IF(_rankfortag1=1,CALCULATE(SUM('Forecast Code'[Shipment QTY]),FILTER(ALLEXCEPT('Forecast Code','Forecast Code'[BC],'Forecast Code'[Customer]),'Forecast Code'[rank]>=_rank&&'Forecast Code'[rank]<=_nextrank)),IF(_rankfortag1>1,CALCULATE(SUM('Forecast Code'[Shipment QTY]),FILTER(ALLEXCEPT('Forecast Code','Forecast Code'[BC],'Forecast Code'[Customer]),'Forecast Code'[rank]>_rank&&'Forecast Code'[rank]<=_nextrank)
)))

Result:

1.JPG

 

here is sample pbix file, please try it.

 

Regards,

Lin

 

 

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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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