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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
domdom
Helper II
Helper II

counting date instances occurring for last 2 months by user

Hello,

 

I have a question if you are able to help with it.  I have the following table of dates against user_ids (these will be updating frequently about 20,000 records):

 

TABLE A:

----------------------

date                      user_id

20/02/2016           A

22/02/2016           C

27/02/2016           D

04/03/2016           C

06/03/2016           C

01/04/2016           C

01/04/2016           A

30/04/2016           B

05/05/2016           C

06/05/2016           B

26/05/2016           A

01/06/2016           B

01/09/2016           C

 

 

I'd like to add another column to this same table which counts the total dates that exist between the date of the current record less 2 months for each user_id.  E.g.  for the value against the date 05/05/2016 for user_id C - it should count the total dates in the table between 05/03/2016 to 05/05/2016 that also have a user_id of C- so it would show 3 - as the following dates fall within this range:

 

06/03/2016           C

01/04/2016           C

05/05/2016           C

 

hope that makes senses?

 

 

Using my sample data - the final table should look as follows:

 

TABLE A:

----------------------

date                      user_id          total dates less 2 months by user

20/02/2016           A                   1

22/02/2016           C                   1

27/02/2016           D                   1 

04/03/2016           C                   2 

06/03/2016           C                   3

01/04/2016           C                   4

01/04/2016           A                   2

30/04/2016           B                   1

05/05/2016           C                   3

06/05/2016           B                   2

26/05/2016           A                   2

01/06/2016           B                   3

01/09/2016           C                   1  

 

If you are able to help with this it would be most appreciated!

 

many thanks

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@domdom

 

Hi,

 

Please try this column

 

Column =
VAR CurrentDate = Table1[date ]
VAR TwoMonthsbefore =
    DATE ( YEAR ( CurrentDate ), MONTH ( CurrentDate ) - 2, DAY ( CurrentDate ) )
RETURN
    CALCULATE (
        COUNTROWS ( Table1 ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[user_id ] ),
            Table1[date ] <= CurrentDate
                && Table1[date ] >= TwoMonthsbefore
        )
    )

View solution in original post

3 REPLIES 3
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @domdom,

 

Could you please mark the proper answers as solutions?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Zubair_Muhammad
Community Champion
Community Champion

@domdom

 

Hi,

 

Please try this column

 

Column =
VAR CurrentDate = Table1[date ]
VAR TwoMonthsbefore =
    DATE ( YEAR ( CurrentDate ), MONTH ( CurrentDate ) - 2, DAY ( CurrentDate ) )
RETURN
    CALCULATE (
        COUNTROWS ( Table1 ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[user_id ] ),
            Table1[date ] <= CurrentDate
                && Table1[date ] >= TwoMonthsbefore
        )
    )

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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