Although I have some confusion on your opening balance consideration, you can achieve your required output with couple of Custom Column and Measures given below-
First of all lets create a Date Custom Column to check dates using value from FinYear and FinMonth for all months as below-
first_date_of_month = DATE(your_table_name[finyear],your_table_name[finmonth],1)
Now create this below 2 more Custom Column where from we can check the row belongs to Opening date regards to corresponding Branch and FinYear.
is_initial_opening_of_branch =
var current_row_branch = your_table_name[branch]
var current_row_first_date_of_month = your_table_name[first_date_of_month]
var check_first_balance_of_branch =
CALCULATE(
COUNTROWS(your_table_name),
FILTER(
ALL(your_table_name),
your_table_name[branch] = current_row_branch
&& your_table_name[first_date_of_month] <= current_row_first_date_of_month
)
)
return IF(check_first_balance_of_branch = 1,1,0)
is_initial_opening_of_finyear =
var current_row_branch = your_table_name[branch]
var current_row_finyear = your_table_name[finyear]
var current_row_first_date_of_month = your_table_name[first_date_of_month]
var check_first_balance_of_branch_finyear =
CALCULATE(
COUNTROWS(your_table_name),
FILTER(
ALL(your_table_name),
your_table_name[branch] = current_row_branch
&& your_table_name[finyear] = current_row_finyear
&& your_table_name[first_date_of_month] <= current_row_first_date_of_month
)
)
return IF(check_first_balance_of_branch_finyear = 1,1,0)
Now lets create your required 2 measure as below-
ltd_opening =
var current_row_branch = MIN(your_table_name[branch])
var current_row_first_date_of_month = MIN(your_table_name[first_date_of_month])
return
CALCULATE(
sum(your_table_name[nett]),
FILTER(
ALL(your_table_name),
your_table_name[branch] = current_row_branch
&& your_table_name[first_date_of_month] <= current_row_first_date_of_month
&& your_table_name[is_initial_opening_of_branch] <> 1
)
) + 0
ytd_opening =
var current_row_branch = MIN(your_table_name[branch])
var current_row_finyear = MIN(your_table_name[finyear])
var current_row_first_date_of_month = MIN(your_table_name[first_date_of_month])
return
CALCULATE(
sum(your_table_name[nett]),
FILTER(
ALL(your_table_name),
your_table_name[branch] = current_row_branch
&& your_table_name[finyear] = current_row_finyear
&& your_table_name[first_date_of_month] <= current_row_first_date_of_month
&& your_table_name[is_initial_opening_of_finyear] <> 1
)
) + 0
Here is the final output-
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…