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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

DAX - for opening and closing column

Hi there

 

In PBI, i have a data table of Month, Batch and Exit numbers setup as below.

 

May I know how can I have:

-a column for Closing, which sequentially minus away (from Batch 1 to 4) the Exit number from an opening number.

-a column for Opening, which takes the last calculated Closing number.

 

Sample output per below.

 

thanks!

 

MonthBatchExitColumn - OpeningColumn - Closing
Jan-1811001000900
Jan-182200900700
Jan-183300700400
Jan-184300400100
1 ACCEPTED SOLUTION
PattemManohar
Community Champion
Community Champion

@Anonymous  Please try this as a new column

 

ColumnClosing = 
VAR _Sum = CALCULATE(SUM(Test194GrpRunningTotal[Exit]),ALLEXCEPT(Test194GrpRunningTotal,Test194GrpRunningTotal[Month]))
VAR _Closing = CALCULATE(SUM(Test194GrpRunningTotal[Exit]),FILTER(Test194GrpRunningTotal,Test194GrpRunningTotal[Batch]<=EARLIER(Test194GrpRunningTotal[Batch]) && Test194GrpRunningTotal[Batch]<>1))
RETURN _Sum-IF(ISBLANK(_Closing),0,_Closing)

Then add another new column for ColumnOpening as below

 

ColumnOpening = Test194GrpRunningTotal[ColumnClosing] + Test194GrpRunningTotal[Exit]

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




View solution in original post

2 REPLIES 2
PattemManohar
Community Champion
Community Champion

@Anonymous  Please try this as a new column

 

ColumnClosing = 
VAR _Sum = CALCULATE(SUM(Test194GrpRunningTotal[Exit]),ALLEXCEPT(Test194GrpRunningTotal,Test194GrpRunningTotal[Month]))
VAR _Closing = CALCULATE(SUM(Test194GrpRunningTotal[Exit]),FILTER(Test194GrpRunningTotal,Test194GrpRunningTotal[Batch]<=EARLIER(Test194GrpRunningTotal[Batch]) && Test194GrpRunningTotal[Batch]<>1))
RETURN _Sum-IF(ISBLANK(_Closing),0,_Closing)

Then add another new column for ColumnOpening as below

 

ColumnOpening = Test194GrpRunningTotal[ColumnClosing] + Test194GrpRunningTotal[Exit]

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Anonymous
Not applicable

thank you @PattemManohar !

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.