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, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Luke_Howells
Helper I
Helper I

Distinct Count on a Rolling Month

Hi All,

 

I have a table of data which contain a date column, site name column and an audit score column. What I want to do is be able to have a calculation that can show the number of sites that have been audited throughout each month on a rolling basis. The data table looks like:

 

Luke_Howells_0-1618502797643.png

 

I also have a date table which I use for a date filter. Each site may appear more than once per month which is why it needs to be a distinct count (or I think so). I have managed to work out how many sites have been audited on each date but want to have an acummalting column that would reset with each first day of the month (hence the first day column below). I was hoping the calculation would produce what is column EXAMPLE below:

 

NOTE: Column measure is what I have managed to write which works out how many sites have been audited on each date. 

 

Luke_Howells_1-1618503124943.png

 

 

 

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @Luke_Howells 

You can create a Measure like this:

 

AccumulateAuditSiteByMonth =

VAR res =

    CALCULATE (

        [CountAuditSite],

        FILTER ( ALL ( 'dataTable' ), 'dataTable'[Date] <= MAX ( 'dataTable'[Date] ) ),

        FILTER (

            ALLSELECTED ( dateTable ),

            dateTable[Start of Month] = MAX ( dateTable[Start of Month] )

        )

    )

RETURN

    IF ( HASONEFILTER ( dateTable[Start of Month] ), res, [CountAuditSite] )

 

The result looks like this:

v-cazheng-msft_0-1618811910709.png

 

For more details, you can refer the attached pbix file.

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? 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

3 REPLIES 3
v-cazheng-msft
Community Support
Community Support

Hi @Luke_Howells 

You can create a Measure like this:

 

AccumulateAuditSiteByMonth =

VAR res =

    CALCULATE (

        [CountAuditSite],

        FILTER ( ALL ( 'dataTable' ), 'dataTable'[Date] <= MAX ( 'dataTable'[Date] ) ),

        FILTER (

            ALLSELECTED ( dateTable ),

            dateTable[Start of Month] = MAX ( dateTable[Start of Month] )

        )

    )

RETURN

    IF ( HASONEFILTER ( dateTable[Start of Month] ), res, [CountAuditSite] )

 

The result looks like this:

v-cazheng-msft_0-1618811910709.png

 

For more details, you can refer the attached pbix file.

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Luke_Howells
Helper I
Helper I

@amitchandak Thanks for the help but the data in the table goes back for a couple of years and ideally want the rolling total column not to haave a fixed date in there if possible? Hope that makes sense?

amitchandak
Super User
Super User

@Luke_Howells , to me it seems like YTD with an end date of March 

 

example

YTD Sales = CALCULATE([measure],DATESYTD('Date'[Date],"3/31"))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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.