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
_smolar
Frequent Visitor

Last 3 months (excluding the given month) calculations table for each month

I'm having trouble creating the table with the number of records from last 3 months (excluding the given month).

I have a table "Query" with the records ID and with the dates they were created/opened. Every ID is unique.
Query

Record IDDate Opened
213821614/01/2022
218335728/01/2022
220313401/02/2022
220647702/02/2022
220842215/02/2022
221368417/02/2022
222093203/03/2022
222216607/03/2022
221802319/03/2022
222864021/04/2022
223621029/04/2022


I need to create a table that in a given month will show the number of records from the last 3 months (counting from the month before so we exclude given month). What I am expecting are results like:

DateNumber of records
Jan 20220
Feb 20222
Mar 20226
Apr 20229
May 202211


I would like the data to be updated based on the entered "Date Opened", i.e. if new months appear when the table is refreshed, they will be added to the table.

So far, the only thing I have managed to create is the formula to calculate the number of records from the last 3 months. I built the Date Dimension table based on the "Date Opened" from the "Query". This is the measure:

last3months =
VAR EndDate =
EOMONTH('DateDimension'[MonthYear],-1)       ----- end of the previous month as an end date for calculation
 
VAR StartDate =
EOMONTH('DateDimension'[MonthYear],-4)+1   ---- end of the month 4 months earlier + 1 day to create the start day for calculation
 
VAR Result =
CALCULATE(
COUNTA('Query'[Record ID]),                              
DATESBETWEEN('Query'[Date Opened], StartDate, EndDate)   ----- count number of records between these dates
)
RETURN
Result


When I'm trying to create the table, the results are like below and I'm stuck at this point because I would like to have a division into months, not days.

Date OpenedNumber of records
14/01/20220
28/01/20220
01/02/20222
02/02/20222
15/02/20222
17/02/20222
03/03/20226
07/03/20226
19/03/20226
21/04/20229
29/04/20229


Many thanks! 🙂 

2 REPLIES 2
Anonymous
Not applicable

Hi @_smolar ,

 

Please try this measure:

Number of Records = 
VAR _maxdate =
    EDATE ( MAX ( 'Calendar'[Date] ), -1 )
VAR _mindate =
    EDATE ( MAX ( 'Calendar'[Date] ), -4 ) + 1
VAR _num =
    CALCULATE (
        COUNT ( 'Table'[Record ID] ),
        FILTER (
            ALL('Table'),
            'Table'[Date Opened] >= _mindate
                && 'Table'[Date Opened] <= _maxdate
        )
    ) + 0
RETURN
    _num

vcgaomsft_0-1663206916715.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Hello @v-cgao-msft ,

Thank you for the quick reply. I tried your way but I have 2 problems:

1. the dates are not chronological. They are as in the pic below, so they are arranged alphabetically:

_smolar_0-1663236730610.png_smolar_1-1663236730166.png

 

I  tried to create the table with the 'Date' as a value, not 'Month Year' and it looks better if it comes to chronological order, however I would like to have a 'Month Year' in the table. 

_smolar_2-1663236730605.png_smolar_3-1663236730167.png



2. The second problem is that the number of records in the newly created table doesn't match the actual value. I wanted to check if it works correctly so I built the table with the number of records we had in particular months. It is simple table with the Date Opened and Record ID values. So for example value for the February 2021 should be 3206 because we had 3206 in January 2021. No. of record for the March 2021 should be 6936 (3730+3206) etc.

 

_smolar_4-1663236730167.png_smolar_5-1663236730168.png

 

Let me know if you need more information regarding these errors. 


Kind Regards,

Katarzyna

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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