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

View all the Fabric Data Days sessions on demand. View schedule

Reply
nok
Advocate II
Advocate II

Count rows for the next six months based on the Quarter dynamically

Hi!

I have two tables that follow this structure:
Calendar

Year-Quarter  Year
2024 Q1        2024   
2024 Q2  2024
2024 Q3  2024
2024 Q4  2024
2025 Q1  2025
2025 Q2  2025
2025 Q3  2025
2025 Q4  2025

 

Sales

Year-Quarter  FileDatePlannedCompletionDate  Status
2024 Q123/03/2024  01/02/2023X
2024 Q219/06/202419/04/2024ScheduledForCompletion
2024 Q330/09/202413/07/2024X
2024 Q413/12/202422/12/2024ScheduledForCompletion
2025 Q130/03/202504/02/2025ScheduledForCompletion
2025 Q230/06/202530/11/2025X
2025 Q330/09/202519/09/2025X
2025 Q330/09/202527/09/2025ScheduledForCompletion
2025 Q426/12/202523/11/2025ScheduledForCompletion


In my dashboard, I have a "Year-Quarter" filter coming from the Calendar table. My two tables are related by the Year-Quarter column. I want to create a measure that counts rows in my Sales table where it checks, in the FileDate column, which date refers to the Year-Quarter filtered by the user and then counts the number of rows where the Status column = "ScheduledForCompletion" and the PlannedCompletionDate column is in the next 6 months from the specified FileDate.

Example 1: If the user filters 2025 Q2, the measure should show the value 3 because based on the FileDate for 2025 Q2 (30/06/2025), there are three rows with "ScheduledForCompletion" status in the next six months:

2025 Q3  30/09/2025  27/09/2025  ScheduledForCompletion
2025 Q4 26/12/202523/11/2025ScheduledForCompletion
2024 Q413/12/202422/12/2025ScheduledForCompletion


Example 2: If the user filters 2024 Q4, the measure should show the value 2 because based on the FileDate for 2024 Q4 (13/12/2024), there are two rows with "ScheduledForCompletion" status in the next six months:

2024 Q4 13/12/2024  22/12/2024 ScheduledForCompletion
2025 Q1 30/03/202504/02/2025ScheduledForCompletion


How can I do that measure?

1 ACCEPTED SOLUTION
KarinSzilagyi
Impactful Individual
Impactful Individual

@nok Hello again 😅

Did you mean something like this:

Count Scheduled Next 6M = 
VAR SelQ =
    SELECTEDVALUE ( 'Calender'[Year-Quarter] )
VAR RefDate =
    CALCULATE (
        MAX ( FactSales[FileDate] ),
        FILTER (
            ALL ( FactSales[Year-Quarter], FactSales[FileDate] ),
            FactSales[Year-Quarter] = SelQ
        )
    )
VAR EndDate = EDATE ( RefDate, 6 )
RETURN
IF (
    ISBLANK ( RefDate ),
    BLANK (),
    CALCULATE (
        COUNTROWS ( FactSales ),
        KEEPFILTERS ( FactSales[Status] = "ScheduledForCompletion" ),
        KEEPFILTERS ( FactSales[PlannedCompletionDate] >= RefDate ),
        KEEPFILTERS ( FactSales[PlannedCompletionDate] <= EndDate ),
        ALL ( 'Calender' ),
        ALL ( FactSales[Year-Quarter] )
    )
)

KarinSzilagyi_0-1759770333484.png

 



Did I answer your question? If so, please consider marking my response as the ‘Accepted Solution’ - it helps others with the same issue find the answer more easily!

View solution in original post

2 REPLIES 2
KarinSzilagyi
Impactful Individual
Impactful Individual

@nok Hello again 😅

Did you mean something like this:

Count Scheduled Next 6M = 
VAR SelQ =
    SELECTEDVALUE ( 'Calender'[Year-Quarter] )
VAR RefDate =
    CALCULATE (
        MAX ( FactSales[FileDate] ),
        FILTER (
            ALL ( FactSales[Year-Quarter], FactSales[FileDate] ),
            FactSales[Year-Quarter] = SelQ
        )
    )
VAR EndDate = EDATE ( RefDate, 6 )
RETURN
IF (
    ISBLANK ( RefDate ),
    BLANK (),
    CALCULATE (
        COUNTROWS ( FactSales ),
        KEEPFILTERS ( FactSales[Status] = "ScheduledForCompletion" ),
        KEEPFILTERS ( FactSales[PlannedCompletionDate] >= RefDate ),
        KEEPFILTERS ( FactSales[PlannedCompletionDate] <= EndDate ),
        ALL ( 'Calender' ),
        ALL ( FactSales[Year-Quarter] )
    )
)

KarinSzilagyi_0-1759770333484.png

 



Did I answer your question? If so, please consider marking my response as the ‘Accepted Solution’ - it helps others with the same issue find the answer more easily!
d_m_LNK
Resolver III
Resolver III

I would start with something like this below.  Also Maybe consider adding a date column to the calendar table and join the calendar table to the filedate column (if possible):


VAR _sixMonths = DateAdd(Sales[FileDate], 6, Month)

VAR _FileDate = SELECTEDVALUE(Sales[Filedate))

VAR Result = 

CALCULATE(COUNTROWS(Sales), Sales[ScheduledForCompletion] = "ScheduledForCompletion", DatesBetween(Sales[PlannedCompletionDate], _FileDate, _sixMonths))

RETURN Result

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors