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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Eric-De
Frequent Visitor

FILTER and PREVIOUSMONTH function DAX , how to combine

Under powerautomate I used the PowerBI dataset to export some values under excell file, and I need to filter on the previousmonth only. 
For this I have create a calendar table to compare with the date closed under the table Tickets but when I implent the 
FILTER ( Tickets, Tickets[closed] = PREVIOUSMONTH(Calendar[Date])) 
instead of
FILTER ( Tickets, Tickets[closed] < DATE(YEAR(today()),MONTH(today()),1) && Tickets[closed] >= DATE(YEAR(today()),MONTH(today())-1,1) )
that return nothing
 
Here my script DAX who running
Can you help me to use corectly the PREVIOUSMONTH function for this ? 
 
// DAX Query
 
DEFINE
  VAR vType =   TREATAS({"CPU", "MEM","DISK"}, Tickets[Service])
 
EVALUATE
  SUMMARIZECOLUMNS
  (
    ROLLUPADDISSUBTOTAL
    (
      Tickets[Service], "Type", vType,
      TREATAS ( { "OK" }, Tickets[Status] ),
  FILTER( Tickets , RELATED(ServiceOffering[Service Offering]) ="TOP" ),
  FILTER ( Tickets, Tickets[closed] < DATE(YEAR(today()),MONTH(today()),1) && Tickets[closed] >= DATE(YEAR(today()),MONTH(today())-1,1) )
    ),
    "Total Qty", COUNT(Tickets[Target])
  )
 
ORDER BY
  [Type] DESC, [Service]
  
 
 
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

 

DEFINE
  VAR vType =   TREATAS({"CPU", "MEM","DISK"}, Tickets[Service])
 
EVALUATE
  SUMMARIZECOLUMNS
  (
    ROLLUPADDISSUBTOTAL
    (
      Tickets[Service], "Type", vType,
      TREATAS ( { "OK" }, Tickets[Status] ),
  FILTER( Tickets , RELATED(ServiceOffering[Service Offering]) ="TOP" ),
  FILTER ( Dates, PREVIOUSMONTH(Dates[Date] )
    ),
    "Total Qty", COUNT(Tickets[Target])
  )

 

This assumes you have a Dates table in your data model and that it is joined to the Close Date.

View solution in original post

2 REPLIES 2
Eric-De
Frequent Visitor

Hello 

So need to create a table date for this 
CALENDAR (
    DATE ( YEAR ( MIN ( Tickets[Closed] ) ), 1, 1 ),
    DATE ( YEAR ( MAX ( Tickets[Closed] ) ), 12, 31 )
)
and because column containt date and time problably need o separate the date and time to group result by month
 
But in all case thank for your reply 
lbendlin
Super User
Super User

 

DEFINE
  VAR vType =   TREATAS({"CPU", "MEM","DISK"}, Tickets[Service])
 
EVALUATE
  SUMMARIZECOLUMNS
  (
    ROLLUPADDISSUBTOTAL
    (
      Tickets[Service], "Type", vType,
      TREATAS ( { "OK" }, Tickets[Status] ),
  FILTER( Tickets , RELATED(ServiceOffering[Service Offering]) ="TOP" ),
  FILTER ( Dates, PREVIOUSMONTH(Dates[Date] )
    ),
    "Total Qty", COUNT(Tickets[Target])
  )

 

This assumes you have a Dates table in your data model and that it is joined to the Close Date.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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