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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Calculate previous month sales date wise

Hi Team,

 

Previously, thanks for help.

 

I have to calculate previous month sales but in day wise. For example, if today's date is 29th June 2022 then previous month sales come only 1st May 2022 to 29th May 2022.

 

I have used the below formula:

 

Previous month sales  = CALCULATE(SUM(tableA[Sales]), DATEADD(DATESMTD("calcnder'[date]), -1, MONTH))

 

But, this formula is showing till 31-may-2022 sales.

 

Please help me on this

 

Thanks

Shipra

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous ,

I created some data:

vyangliumsft_0-1656990573828.png

Here are the steps you can follow:

1. Create measure.

Measure =
SUMX(
   ALLSELECTED('Table'),'Table'[Amount])
Flag =
var _today=TODAY()
var _date1=DATE(YEAR(_today),MONTH(_today)-1,1)
var _date2=DATE(YEAR(_today),MONTH(_today)-1,DAY(_today))
return
IF(
    MAX('Table'[Date])>=_date1&&MAX('Table'[Date])<=_date2,1,0)

2. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_1-1656990573829.png

3. Result:

vyangliumsft_2-1656990573830.png

If you need pbix, please click here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

mh2587
Super User
Super User

var currentDate = LASTDATE('Date Table'[Date])
var pre30Days = DATEADD(LASTDATE('Date Table'[Date]),-1,MONTH)
var _Sale = CALCULATE([Total Sale],DATESBETWEEN('Date Table'[Date],pre30Days,currentDate))
   return _sale
//Try this

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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

Top Solution Authors
Top Kudoed Authors