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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Previous Month Sales on no of days in current month

Hi,
 
If I use this code it shows blank in the start of month on 1st day of every month for rest of the months it works properly.
 
what i'm trying to achieve here is showing sales of same no of days in previous month as no of days in current month.
 
So for eg if in current month it is 4 days sales then in previous month also it will show sales of 4 days only.
 
PM  =
VAR currentmonthstart =
DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 )
VAR currentday =
TODAY () -1
VAR currentdiff =
DATEDIFF ( currentmonthstart, currentday, DAY )
VAR previousmonthstart =
EOMONTH ( TODAY (), -2 ) + 1
VAR PreviousMonthValue =
CALCULATE (
SUM ( 'Table'[Sales] ),
FILTER (
'Date',
'Date'[Date] >= previousmonthstart
&& 'Date'[Date] <= previousmonthstart + currentdiff
)
)
RETURN
PreviousMonthValue
4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

Is your problem solved? If so, Would you mind accept the helpful replies as solutions? Then we could close the thread. More people who have the same requirement will find the solution quickly and benefit here. Thank you.

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

After my test, I don't understand the reason why your first day is blank. In my case, I worked on the first day of the beginning of the month.

vyalanwumsft_0-1638772538440.png

So can you share some screenshots and scenes about your mistake?

 

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Try using time intelligece or force it

 

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

 

 

///forced 

MTD QTY forced=
var _max = maxx(allselected(Date), Date[Date])
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESMTD('Date'[Date])), blank())
//or
//calculate(Sum('order'[Qty]),DATESMTD('Date'[Date]),filter('Date','Date'[Date]<=_max))
//calculate(TOTALMTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))


LMTD QTY forced=
var _max1 = maxx(allselected(Date), Date[Date])
var _max = date(year(_max1), Month(_max1)-1, day(_max1))
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date]),-1,month)), blank())
//or

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

I tried using this dax but it is not working it is showing sales for overall month instead of sales of no of days in previous month as current month

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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