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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
akhaliq7
Continued Contributor
Continued Contributor

datesinperiod but for start date use previous month as only need to report on complete/whole months

I have the following datesinperiod code:

 

Table = 
 CALCULATETABLE(
     'Table',
     DATESINPERIOD(
         'Date'[Date],
         PREVIOUSMONTH(MAX('Date'[Date])),
         -12,
         MONTH
     )
)

 

But want the start date to be the previous month as only reporting on complete/whole months. e.g. today is 01/06/2023 so need my max date to be 31st of may 2023 and need the date to start 1st of june 2022

1 ACCEPTED SOLUTION
akhaliq7
Continued Contributor
Continued Contributor

I managed to solve my issue using the following code:

Table = 
CALCULATETABLE(
    'Table',
    DATESINPERIOD(
        'Date'[Date],
        EOMONTH(MAX('Date'[Date]), -1),
        -13,
        MONTH
    )
)

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

Hi @akhaliq7 

please try

Table =
CALCULATETABLE (
'Table',
FILTER (
DATESINPERIOD (
'Date'[Date],
PREVIOUSMONTH ( MAX ( 'Date'[Date] ) ),
-12,
MONTH
),
FORMAT ( 'Date'[Date], "YYMM" ) < FORMAT ( TODAY (), "YYMM" )
)
)

akhaliq7
Continued Contributor
Continued Contributor

I managed to solve my issue using the following code:

Table = 
CALCULATETABLE(
    'Table',
    DATESINPERIOD(
        'Date'[Date],
        EOMONTH(MAX('Date'[Date]), -1),
        -13,
        MONTH
    )
)

Based on your explanation, you need to make it -12 instead of -13... Using -13 would make the range: May 1, 2022 - May 31 2023; using -12 would make it  June 1, 2022 - May 31, 2023.

akhaliq7
Continued Contributor
Continued Contributor

Just to add when I created my date table I have set max date to today()

akhaliq7
Continued Contributor
Continued Contributor

I am getting the following error message: The first argument to 'PREVIOUSMONTH' must specify a column.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors