cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors