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
Velvetine27
Helper I
Helper I

Get the data for previous of MAX month

Hi,

 

I'm looking for ways to get data for PREVIOUSMONTH if we select multiple months. I just need the data for the previous month of the max selected date. If we select Jan till June, i want the sales data for May, which is the same if I select June only.
I've tried CALCULATE([SalesSum],FILTER(CalendarTable, DATEADD(CalendarTable[Date], -1,MONTH))) but it doesn't work. Appreciate any help here.

 

Thanks !

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Velvetine27 

 

You can try the following methods

Sample data:

vzhangti_0-1687758767630.png

Measure = CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),[Month]=MAX('Table'[Month])-1))

vzhangti_1-1687758806426.pngvzhangti_2-1687758817736.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi, @Velvetine27 

 

You can try the following methods

Sample data:

vzhangti_0-1687758767630.png

Measure = CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),[Month]=MAX('Table'[Month])-1))

vzhangti_1-1687758806426.pngvzhangti_2-1687758817736.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

devanshi
Helper V
Helper V

MaxSelectedDate = MAX('Table'[Date])
PreviousMonthSales = CALCULATE( SUM('Table'[Sales]),
                                                            DATEADD('Table'[Date], -1, MONTH) = [MaxSelectedDate] )

Hi, there's an error to this dax, "A function 'DATEADD' has been used in a True/False expression that is used as a table filter expression. This is not allowed." 

TRY this once, 
MaxSelectedDate = MAX('Table'[Date])

PreviousMonthSales = CALCULATE( SUM('Table'[Sales]),
                                                           DATESINPERIOD('Table[Date],MaxSelectedDate, -1,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