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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
AbhinavJoshi
Responsive Resident
Responsive Resident

Help Creating a Count Measure

Hi,

 

I am looking to get a count of accounts where election date would be in next month period. Also, I have a coverage date range slicer so that the user can select the date range.
I have the following formula but it is not working correctly

 

 

 

NextMonthReenrollments =
VAR SelectedStartDate = MIN('Accounts'[Coverage Election])
VAR SelectedEndDate = MAX('Accounts'[Coverage Election])

VAR NextMonthStart = EOMONTH(TODAY(), 0) + 1
VAR NextMonthEnd = EOMONTH(TODAY(), 1)

VAR Result =
CALCULATE(
    COUNTROWS('Accounts'),
    FILTER(
        'Accounts',
        'Accounts'[Coverage Election] >= NextMonthStart &&
        'Accounts'[Coverage Election] <= NextMonthEnd &&
        'Accounts'[Coverage Election] >= SelectedStartDate &&
        'Accounts'[Coverage Election] <= SelectedEndDate
    )
)

RETURN
IF(ISBLANK(Result), 0, Result)

 

 


Sample data

160Account 12025-01-01
869Account 22024-11-19
871Account 32026-06-01
872Account 42024-11-01
1153Account 52025-01-01
1313Account 62024-11-01
1312Account 72024-11-01
1235Account 82024-11-01
1236Account 92024-11-01
1242Account 102025-01-01
1245Account 112025-01-01
1260Account 122025-04-02
1395Account 132025-01-01
1396Account 142025-01-01
1397Account 152025-01-01
1399Account 162026-01-01
1400Account 172026-01-01
1401Account 182025-01-01
1402Account 192025-01-01
1398Account 202025-01-01
1403Account 212025-01-01
1432Account 222025-01-01
1443Account 232025-01-01
1577Account 242025-01-01
1565Account 252025-01-01
1566Account 262025-01-01
1567Account 272025-10-01
1591Account 282026-01-01
1593Account 292025-01-01
1599Account 302025-01-01
1602Account 312026-02-01
2057Account 322026-06-01
2060Account 332025-01-01
2071Account 342024-11-01
2091Account 352025-01-01
2173Account 362025-01-01
2164Account 372025-04-01
2165Account 382025-01-01
2177Account 392025-01-01
2230Account 402025-01-01
2242Account 412025-01-01
2227Account 422025-01-01
2233Account 432025-01-01
2226Account 442025-01-01
2239Account 452025-01-01
2228Account 462025-01-01
2234Account 472025-01-01
2238Account 482025-01-01
2235Account 492025-01-01
2237Account 502025-01-01
2236Account 512025-01-01
2272Account 522025-01-01
2282Account 532025-07-01

 

Sample slicer

AbhinavJoshi_0-1729875469339.png


Thank you in advance for helping.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @AbhinavJoshi ,

When the slicer's date range is from 2025-03-01 to 2026-05-01, it is correct to return the number of account numbers as 0. Because according to your formula, it will return the below values for the following variables in your formula. 

Variable Value
SelectedStartDate 2025-03-01
SelectedEndDate 2026-05-01
NextMonthStart 2024-11-01
NextMonthEnd 2024-11-30
 And the conditions will changed as below. The two conditions in red are in conflict, and there is no account in the table that meets both conditions. Therefore, the number of accounts returns 0.
'Accounts'[Coverage Election] >= "2024-11-01" &&
'Accounts'[Coverage Election] <= "2024-11-30" &&
'Accounts'[Coverage Election] >= "2025-03-01" &&
'Accounts'[Coverage Election] <= "2026-05-01"
NextMonthReenrollments =
VAR SelectedStartDate = MIN('Accounts'[Coverage Election])
VAR SelectedEndDate = MAX('Accounts'[Coverage Election])

VAR NextMonthStart = EOMONTH(TODAY(), 0) + 1
VAR NextMonthEnd = EOMONTH(TODAY(), 1)

VAR Result =
CALCULATE(
    COUNTROWS('Accounts'),
    FILTER(
        'Accounts',
        'Accounts'[Coverage Election] >= NextMonthStart &&
        'Accounts'[Coverage Election] <= NextMonthEnd &&
        'Accounts'[Coverage Election] >= SelectedStartDate &&
        'Accounts'[Coverage Election] <= SelectedEndDate
    )
)

RETURN
IF(ISBLANK(Result), 0, Result)

Best Regards

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @AbhinavJoshi ,

When the slicer's date range is from 2025-03-01 to 2026-05-01, it is correct to return the number of account numbers as 0. Because according to your formula, it will return the below values for the following variables in your formula. 

Variable Value
SelectedStartDate 2025-03-01
SelectedEndDate 2026-05-01
NextMonthStart 2024-11-01
NextMonthEnd 2024-11-30
 And the conditions will changed as below. The two conditions in red are in conflict, and there is no account in the table that meets both conditions. Therefore, the number of accounts returns 0.
'Accounts'[Coverage Election] >= "2024-11-01" &&
'Accounts'[Coverage Election] <= "2024-11-30" &&
'Accounts'[Coverage Election] >= "2025-03-01" &&
'Accounts'[Coverage Election] <= "2026-05-01"
NextMonthReenrollments =
VAR SelectedStartDate = MIN('Accounts'[Coverage Election])
VAR SelectedEndDate = MAX('Accounts'[Coverage Election])

VAR NextMonthStart = EOMONTH(TODAY(), 0) + 1
VAR NextMonthEnd = EOMONTH(TODAY(), 1)

VAR Result =
CALCULATE(
    COUNTROWS('Accounts'),
    FILTER(
        'Accounts',
        'Accounts'[Coverage Election] >= NextMonthStart &&
        'Accounts'[Coverage Election] <= NextMonthEnd &&
        'Accounts'[Coverage Election] >= SelectedStartDate &&
        'Accounts'[Coverage Election] <= SelectedEndDate
    )
)

RETURN
IF(ISBLANK(Result), 0, Result)

Best Regards

AbhinavJoshi
Responsive Resident
Responsive Resident

Here

AbhinavJoshi_0-1729882386487.png

 

so based on your sample data from your original post, seems your result is all data from November 2024 all the way until October 2026.  Your earliest data point is only November 19, 2024 so getting all but 3 records seems correct.

 

Is that what you're looking for? If not, you'll need to make some tweaks to one or more of your dates.



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
AbhinavJoshi
Responsive Resident
Responsive Resident

Hi,

It removed all the filters and gave me a count of all accounts withouth respecting any filters from date slilcer.

Hi @AbhinavJoshi 

Can you replace your last line with this?

SelectedStartDate & " - " & SelectedEndDate & " | " & NextMonthStart & " - " & NextMonthEnd 

 

Then share with me your results. 



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
hnguy71
Super User
Super User

Hi @AbhinavJoshi ,

Because your next month data is currently out of range in context, you'll need to add an ALL to remove filter context. Try this instead:

NextMonthReenrollments =
VAR SelectedStartDate = MIN('Accounts'[Coverage Election])
VAR SelectedEndDate = MAX('Accounts'[Coverage Election])

VAR NextMonthStart = EOMONTH(TODAY(), 0) + 1
VAR NextMonthEnd = EOMONTH(TODAY(), 1)

VAR Result =
CALCULATE(
    COUNTROWS('Accounts'),
    FILTER(
        ALL('Accounts'),
        'Accounts'[Coverage Election] >= NextMonthStart &&
        'Accounts'[Coverage Election] <= NextMonthEnd ||
        'Accounts'[Coverage Election] >= SelectedStartDate &&
        'Accounts'[Coverage Election] <= SelectedEndDate
    )
)

RETURN
IF(ISBLANK(Result), 0, Result)

 

I also updated one of your "and" to "or" to pick up both current selection and next month as well.



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.