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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Latest Day of Last Month

I have two tables, one that has mutliple rows for each date a measure was recorded and another that is my date table.  The date table is a typical date dimension with 1 row per date from 1 JAN 1900 through to the year 3000. There is a Foreign Key specified from the Fact Measurement.DateKey to the date table. 

 

Example Fact Measurement:

 

 

=Fact Measurement=
|Cnt | DateKey|
|100 |20190808|
|110 |20190808|
|100 |20190801|
|110 |20190801|
|22  |20190725|
|333 |20190724|

I would like the find the latest day from last month that has a meausurement in DAX. In the example above, the DAX would return 25 JUL 2019. Next month, it would return 8 AUG 2019. 

 

I can't seem to get close to this with my nearest attempt being:

var eo_last_month = EOMONTH(DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(TODAY())),-1)
    var lm_measure = FILTER(Measurement, 'Date'[Reporting Date] <= eo_last_month)
    var latest_date = CALCULATE(
        MAX('Date'[Reporting Date]),
                lm_measure 
    )    
return latest_date 

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @Anonymous 

Something like this should work:

Latest Date Last Month = 
CALCULATE ( 
    CALCULATE ( MAX ( 'Date'[Reporting Date] ), 'Measurement' ),
    PARALLELPERIOD ( TREATAS({TODAY()},'Date'[Reporting Date]), -1, MONTH )
)

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @Anonymous 

Something like this should work:

Latest Date Last Month = 
CALCULATE ( 
    CALCULATE ( MAX ( 'Date'[Reporting Date] ), 'Measurement' ),
    PARALLELPERIOD ( TREATAS({TODAY()},'Date'[Reporting Date]), -1, MONTH )
)

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
Anonymous
Not applicable

Thanks @OwenAuger , that worked perfectly!

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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