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
Ramees_123
Helper IV
Helper IV

DAX Query for calculated column which refers the previous month end data

Below is my avaiable dataset. My dataset contains the product details with date field with has all the month end dates alone.

 

I need to create the below highlighted calculated column "Previous Amount" which takes the amount field of the previous month end date and populates. 

 

How to do it ? Product Name and Facility Type are combined to be unique identifier. 

 

Ramees_123_0-1618481902445.png

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Ramees_123 , for a new column

 

New column =
var _prd = [product name]
var _typ = [facility Type]
var _pd = [previous date]
return
sumx(filter(Table, [product name] = _prd && [facility Type] =_typ && [Date] =_pd), Amount)

 

For measure use date table and create measures like

 

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

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Ramees_123 , for a new column

 

New column =
var _prd = [product name]
var _typ = [facility Type]
var _pd = [previous date]
return
sumx(filter(Table, [product name] = _prd && [facility Type] =_typ && [Date] =_pd), Amount)

 

For measure use date table and create measures like

 

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

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.