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
yalla
New Member

last month to date based on current date

If today is November 4 i want to calculate some measures as below requirement 

1. sum(sales) between October 1 to October 4 (i.e last 1 month same period)

 

i tried this measure but giving the result from Oct 1 to Oct 3 but  i want from oct 1 to oct 4th.

 

1-MonthSamePeriod =
CALCULATE (
    SUM ( 'Table'[Sales] ),
    FILTER (
        'Table',
        AND (
            [Date]
                >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 ),
            [Date]
                <= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, DAY ( TODAY () ) - 1 )
        )
    )
)
1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @yalla ,

Since you want to caulate 10-1 to 10-4 in this case based on 11-4, why did you use -1 in Day()?

Just delete -1 in the formula and it should work.

1-MonthSamePeriod = 
CALCULATE (
    SUM ( 'Table'[Sales] ),
    FILTER (
        'Table',
        AND (
            [Date]
                >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 ),
            [Date]
                <= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, DAY ( TODAY () )  )
        )
    )
)

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@yalla , Try like examples

Last MTD QTY forced=
var _max = date(year(today()),month(today())-1,day(today()))
return
CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)

 

or

 

Last MTD QTY forced=
var _max = date(year(today()),month(today())-1,day(today()))
return
if('Date'[Date]<=_max , CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year))), blank())

in if condition is not able to pick date column.do we have other measure

 

v-yingjl
Community Support
Community Support

Hi @yalla ,

Since you want to caulate 10-1 to 10-4 in this case based on 11-4, why did you use -1 in Day()?

Just delete -1 in the formula and it should work.

1-MonthSamePeriod = 
CALCULATE (
    SUM ( 'Table'[Sales] ),
    FILTER (
        'Table',
        AND (
            [Date]
                >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 ),
            [Date]
                <= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, DAY ( TODAY () )  )
        )
    )
)

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

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.