You haven't really provided actionable data about what your data looks like and what you want to achieve, but here's a wild west shot from the hip:
declare
@fiscal_year_start date = '20210401',
@FromDate date = '20210301',
@ToDate date = '20210630'
select
sum(case when InvoiceDate between @FromDate and @ToDate then InvoiceAmount else 0 end) as periodAmount,
sum(case when InvoiceDate between case when @ToDate < @fiscal_year_start then dateadd(y,-1,@fiscal_year_start) else @fiscal_year_start end and @ToDate then InvoiceAmount else 0 end) as CurrentYearSales
from InvoiceTable
where InvoiceDate between
case when @ToDate < @fiscal_year_start then dateadd(y,-1,@fiscal_year_start) else @FromDate end
and
@ToDate
- This reply was modified 3 years, 2 months ago by kaj. Reason: Little typo