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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

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
Super User
Super User

@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
Super User
Super User

@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
Super User
Super User

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

-----------------------
Did this help?
Drop a kudo so others can find it ! 😄
Mark as a solution if it helped you make progress on your issue 😃

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.