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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. 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
May PBI 25 Carousel

Power BI Monthly Update - May 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

May 2025 Monthly Update

Fabric Community Update - May 2025

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