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
Dan_Alton
Regular Visitor

Quick DAX help for last month and the preceding month values

Hi - I've got a DAX measure to give me the latest availabe data from a sales table

 

Sales Last Month Sum = VAR endDate = LASTDATE('Sales[Date])
RETURN
CALCULATE(
    SUM('Sales'[Value]),
    'Sales'[Date] = endDate
)
 
How do I get a DAX sum to show the value for the month before? I'd then be looking to show the difference in the latest month from the month that preceeded it - is there a way of doing it without having a Calendar table set up? Any help greatly appreciated!
3 REPLIES 3
FreemanZ
Super User
Super User

hi @Dan_Alton ,

 

Not sure if i fully get you, supposing your sales table look like:

date value
9/1/2023 1
10/1/2023 1
10/2/2023 1
11/1/2023 1
11/2/2023 1
11/3/2023 1
12/1/2023 1
12/2/2023 1
1/1/2024 1
1/2/2024 1
1/3/2024 1
1/4/2024 1

 

try

1) add calculated table like:

dates = 
ADDCOLUMNS(
    CALENDAR(MIN(sales[date]), MAX(sales[date])),
    "yymm", FORMAT([Date], "yy/mm")
)

 

2) relate sales[date] with dates[date]

 

3) plot a table visual with dates[yymm] with a measure like:

TotalPM = 
CALCULATE(
    SUM(sales[value]),
    DATEADD(dates[Date],-1, MONTH)
)

 

it worked like:

FreemanZ_0-1700619498512.png

 

v-yaningy-msft
Community Support
Community Support

Could you please provide the data table without sensitive information and how you expect the output to look like?

hi - my table is very simple - thanks

 

Apr-2337.9
May-2339.2
Jun-2341.0
Jul-2339.6
Aug-2339.5
Sep-2339.1
Oct-2339.9

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.

Top Solution Authors