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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
gambleave
Helper II
Helper II

Setting date ranges within measure

I have a measure in the syntax below to count the number of distinct activities (using another distinctcount measure) in the preceding 12 months from today's date. How might a measure like this be adapted to calculate this value at the end of any given month? For example, I would like to be able to create a bar chart visual by month where this count for the preceding 12 months is taken from the last date of the month. 

 

Thank you!

 

12M Distinct Activity=

VAR endDate =TODAY()
VAR startDate=EDATE(endDate, -12)
RETURN
CALCULATE([Distinct Activity],
ALL(ServiceDetails[Activity Date],
(ServiceDetails[Activity Date] >= startDate
&& ServiceDetails[Activity Date] <= endDate
))
1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @gambleave ,

 

You can create a [End of Month] column first.

The main table may have incomplete dates, so a calendar table is required.

Calendar = CALENDAR(DATE(2022,1,1),DATE(2022,12,31))
End of Month = ENDOFMONTH('Calendar'[Date])

vstephenmsft_0-1656048606313.png

 

Then create a measure to count.

Count =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Activity ID] ),
    FILTER (
        ALL ( 'Table' ),
        [Date] = [End of Month]
            && [YearMonth] = MAX ( 'Table'[YearMonth] )
    )
)

vstephenmsft_1-1656048658648.png

 

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-stephen-msft
Community Support
Community Support

Hi @gambleave ,

 

You can create a [End of Month] column first.

The main table may have incomplete dates, so a calendar table is required.

Calendar = CALENDAR(DATE(2022,1,1),DATE(2022,12,31))
End of Month = ENDOFMONTH('Calendar'[Date])

vstephenmsft_0-1656048606313.png

 

Then create a measure to count.

Count =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Activity ID] ),
    FILTER (
        ALL ( 'Table' ),
        [Date] = [End of Month]
            && [YearMonth] = MAX ( 'Table'[YearMonth] )
    )
)

vstephenmsft_1-1656048658648.png

 

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors