Cognos Report Studio筛选需求求助:2月至最后已关账月份数据
Got it, let's work through this dynamic date filtering requirement. The core idea is to calculate your report's date range automatically based on the month when someone runs the report, matching exactly the rules you laid out.
First, let's recap the logic we need to build:
- March–December: Show data from February of the current year up to the last day of the previous month (your last closed month)
- January: Show data from February of the previous year up to December of the previous year
- February: Show data from February of the previous year up to January of the current year
Step 1: Create Dynamic Start/End Date Calculations
In your report's query, add two new data items (name them StartDate and EndDate) with these expressions:
Data Item: StartDate
This defines the beginning of your filtered range:
case -- For Jan/Feb runs: start at Feb of the prior year when extract(month from _current_date) in (1, 2) then date(extract(year from _current_date) - 1, 2, 1) -- For Mar-Dec runs: start at Feb of the current year else date(extract(year from _current_date), 2, 1) end
Data Item: EndDate
This defines the end of your filtered range (the last closed month):
case -- For Jan runs: end at last day of Dec (prior year) when extract(month from _current_date) = 1 then _last_day(date(extract(year from _current_date) - 1, 12, 1)) -- For Feb runs: end at last day of Jan (current year) when extract(month from _current_date) = 2 then _last_day(date(extract(year from _current_date), 1, 1)) -- For Mar-Dec runs: end at last day of the previous month else _last_day(_add_months(_current_date, -1)) end
Step 2: Apply the Filter to Your Query
Now hook these calculated dates into your report's data filter:
- Open the Filter panel for your main query
- Add a condition targeting your date field (e.g.,
TransactionDate):[Your Date Field] >= [StartDate] and [Your Date Field] <= [EndDate] - Make sure the filter is set to Apply Automatically so it runs every time the report is executed.
Step 3: Validate the Logic
Let's confirm this works for each scenario you listed:
- March run:
StartDate= Current Year Feb 1,EndDate= Current Year Feb 28/29 → Only Feb data shows - December run:
StartDate= Current Year Feb 1,EndDate= Current Year Nov 30 → Feb–Nov data shows - January run:
StartDate= Prior Year Feb 1,EndDate= Prior Year Dec 31 → Prior Year Feb–Dec data shows - February run:
StartDate= Prior Year Feb 1,EndDate= Current Year Jan 31 → Prior Year Feb to Current Year Jan data shows
This setup eliminates manual filter updates each month—it'll adjust automatically based on when the report is run.
内容的提问来源于stack exchange,提问作者Sudhakar

