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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. 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
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.

May 2025 Monthly Update

Fabric Community Update - May 2025

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