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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Brightsider
Resolver I
Resolver I

Count number of rows in one table between dates from a different table.

So, I'm working with the following data model, based off of Dynamics:

Brightsider_0-1721334826870.png

 

The formula I'm trying to write is one to count the number of Opportunities which were created within two weeks of an appointment being held with a customer in the Activities table, and to group that data by the System User who created the appointment. There are some challenges to this though: An appointment Activity won't have a direct relationship to the Opportunities that are generated from it, so I relate them by way of the Account ID in both tables. Also, the user who made the appointment Activity won't be the user who owns the Opportunity, since the Appointment is set by one Sales Rep and handed off to an Account Manager to handle the opportunities.

This is the point I've managed to get to with the formula:

 

 

SUMX(
    ADDCOLUMNS(
        FILTER(Activities, Activities[type] = "Appointment"),
        "NewOpportunities",
        CALCULATE(
            COUNTROWS(Opportunities),
            FILTER(Opportunities, 
                Opportunities[DateCreatedMT] >= (Activities[actualend] - 1) && 
                Opportunities[DateCreatedMT] < [actualend]), (Activities[actualend] + 14)) &&
                Opportunities[parentaccountid] = Activities[accountid]
            ),
            Activities[statecodename] = "Completed",
            Activities[type] = "Appointment"
        )
    ),
    [NewOpportunities]
)

 

 

This formula kind of  works: it'll return the number of New Opportunities created after an appointment, but will fail to filter once I try to aggregate it in a table/matrix by the System User. Also, I'm sure there's a less overwrought way of accomplishing what I'm looking for.

Here is the Sample Data.


 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Brightsider ,

Try this DAX expression to see if it meets your needs.

Measure = 

VAR _table = ADDCOLUMNS(FILTER('Activities',[type] = "Appointment" && [statecodename] = "Completed"),"NewOpportunities",
    CALCULATE(COUNTROWS('Opportunities'),
    'Opportunities'[DateCreatedMT] >= EARLIER([actualend]) - 1,
    'Opportunities'[DateCreatedMT] < EARLIER([actualend]) + 14,
    'Opportunities'[parentaccountid] = EARLIER([accountid])
    )
)
RETURN CALCULATE(SUMX(_table,[NewOpportunities]))

vzhouwenmsft_0-1721367457377.png

 

Best Regards,
Wenbin Zhou

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Brightsider ,

Try this DAX expression to see if it meets your needs.

Measure = 

VAR _table = ADDCOLUMNS(FILTER('Activities',[type] = "Appointment" && [statecodename] = "Completed"),"NewOpportunities",
    CALCULATE(COUNTROWS('Opportunities'),
    'Opportunities'[DateCreatedMT] >= EARLIER([actualend]) - 1,
    'Opportunities'[DateCreatedMT] < EARLIER([actualend]) + 14,
    'Opportunities'[parentaccountid] = EARLIER([accountid])
    )
)
RETURN CALCULATE(SUMX(_table,[NewOpportunities]))

vzhouwenmsft_0-1721367457377.png

 

Best Regards,
Wenbin Zhou

So, this solution nearly works! However, if I filter the [title] column from System Users down to just Sales Development Representative, it returns no results, even though I can see from running the measure in the DAX query Editor that it should return numbers for them. What explains this?

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.