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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

October NL Carousel

Fabric Community Update - October 2024

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