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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
semidevil
Helper I
Helper I

Only display data up to previous month (or sum YTD up to previous month)

My data source already has a calendar table for the entire 2018, but my data is still getting updated monthly. I want only display data up to the previous month. So for example, when March comes, I will only display or sum up to the February.

I also need something similar that will sum year to date up to the previous month

What is the best way or measure to do this?
1 ACCEPTED SOLUTION

@semidevil- Try something like this:

 

 

PriorDate = 
var PriorMonthDate = DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY()))
return
CALCULATE(SUM(Table[data]),filter(Table,Table[Date]<PriorMonthDate))

or something along those lines.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
Ana2022
Regular Visitor

@Greg_Deckler - Ive tried this in my measure but the values are not being restricted to the previous month but YTD. Can you help please? Thanks!

 

Ana2022_0-1683211181750.png

 

Hi @Ana2022 -

 

That's really complicated DAX...

 

Three questions:

  1. What are you trying to do?
  2. Do you have a date table and is it marked appropriately?
  3. Can you provide sample data?
littlemojopuppy
Community Champion
Community Champion

Hi!  I came across this looking for a solution for a similar problem.  I wanted to share what I came up with for anyone who might be looking in the future...

    CALCULATE(
        TOTALYTD (
            [Forecasted Contract Count],
            'Calendar'[Date]
        ),
        INTERSECT(
            DATESYTD('Calendar'[Date]),
            PREVIOUSMONTH('Calendar'[Date])
        )
    )

Thank you so much, this works perfectly.

Greg_Deckler
Super User
Super User

Incredibly difficult to say since there is no data given or desired outcome given. But, you could create a date and use it in a FILTER like this:

 

Measure = 
VAR MyDate = DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY()))
RETURN
<do something here where you filter using MyDate>

 

 

 

 

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

thanks.  Here's a sample code.  when I run this,  I seem to get the sum of the entire data, not just from January.

 

PriorDate = 
var PriorMonthDate = DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY()))
return
CALCULATE(SUM(Table[data]),filter(Table,PriorMonthDate))

@semidevil- Try something like this:

 

 

PriorDate = 
var PriorMonthDate = DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY()))
return
CALCULATE(SUM(Table[data]),filter(Table,Table[Date]<PriorMonthDate))

or something along those lines.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.