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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
marukosu
Advocate I
Advocate I

Same period of the last month from a filtered measure

Hello!

 

I created a measure that returns sales per day for certain products, for a certain period of time:

Sales-Campaign = 
CALCULATE(
[Sales],
FILTER( AD_RMPITENSPEDIDOS, AD_RMPITENSPEDIDOS[CODPROD] in VALUES( campaign_itens[Cod Rampap] ) ),
DATESBETWEEN( _Calendario[Data], SELECTEDVALUE( campaigns[camp_start]) , SELECTEDVALUE( campanhas[camp_end] ) )
)

 Is it possible to calculate sales for the same period of days and same products in the previous month?

 

Desired result:

 

DateSales-CampaignSales-Campaign-LM
02/01/202330004500
02/02/202357002000
2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

It will depend upon the structure of underlying data source.  Share data in a format that can be pasted in an MS Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
halfglassdarkly
Responsive Resident
Responsive Resident

You could use: 

 

 

Sales-Campaign-Offset = 
    CALCULATE(
      [Sales], 
      FILTER( AD_RMPITENSPEDIDOS, AD_RMPITENSPEDIDOS[CODPROD] in VALUES( campaign_itens[Cod Rampap] ) ),
      DATESBETWEEN( _Calendario[Data], EDATE(SELECTEDVALUE( campaigns[camp_start])-1) , EDATE(SELECTEDVALUE( campanhas[camp_end] )-1) )
    )

 

 

 But that would still throw an error if your campaign start or end date doesn't exist in the previous month (e.g. if your campaign end date is 31 March EDATE(SELECTEDVALUE( campanhas[camp_end] )-1) is going to throw an error. You could try dealing with that like this, which will sub your selected start and end date for the last day of the previous month if an error is encountered:

 

 

Sales-Campaign-Offset = 
CALCULATE([Sales], 
      FILTER( AD_RMPITENSPEDIDOS, AD_RMPITENSPEDIDOS[CODPROD] in VALUES( campaign_itens[Cod Rampap] ) ),
      DATESBETWEEN( _Calendario[Data], 

      IFERROR(EDATE(SELECTEDVALUE(campaigns[camp_start])-1),EODATE(SELECTEDVALUE( 
      campaigns[camp_start])-1)) , 

      IFERROR(EDATE(SELECTEDVALUE(campanhas[camp_end])-1),EODATE(SELECTEDVALUE( 
      campanhas[camp_end])-1)))
)

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.