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
yforti
Helper II
Helper II

Previous month calculated measures

I need to calculate the total of the (VlConta A Vencer) column for the two months prior to the current month. The current month's data doesn't matter in my model. For example, we are in the month of January, I need to calculate the total of the column VL for the month of December and November, preferably in separate measures.

PS: The measures must be dynamic, because as soon as the month of January closes, the measures must be calculated for the months of December and January and so on.

 

1.JPG

4 REPLIES 4
V-lianl-msft
Community Support
Community Support

Hi @yforti ,

 

Is this problem sloved?
If not, please let me know.

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

yforti
Helper II
Helper II

@amitchandak 

I created a time table as you can see: 

calendario = CALENDAR(DATE(2007,1,1),DATE(2025,1,1))


time.JPG

After that i created a relationship between the Calendario(date) table with the DT_ENTRADA in my database, see below:
e.JPG

The problem is that I'm not getting any results, for example:

I have a sales measure that is:

vl conta = CALCULATE(SUMX('visao_etapa_conta - Não Remetidas','visao_etapa_conta - Não Remetidas'[VL_CONTA]))

, see the result WITHOUT having any relationship with the calendar table:
entrada 2.JPG

See the result after creating the relationship between the tables:
entrada 3.JPG

Why is the result blank when using the time table date?

V-lianl-msft
Community Support
Community Support

Hi @yforti ,

 

Create a Calendar table.
Create the following calculated column to find out the month start date for each transaction date.
Create a relationship between the Date columns of Calendar table and StarDate of fact table.
Create a measure which will find the previous month's sum.

 

 

PrevMonthSum = CALCULATE(  
   SUM('Table'[value]),  
   DATEADD('Table 2'[Date].[Date], -1, MONTH)  
)  

Previous2MonthSum = CALCULATE(  
   SUM('Table'[value]),  
   DATEADD('Table 2'[Date].[Date], -2, MONTH)  
) 

 

 

V-lianl-msft_1-1611644344104.pngV-lianl-msft_2-1611644352950.png

sample .pbix

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@yforti , You can use time intelligence with date table,

 

Refer examples

 

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))
next month Sales = CALCULATE(SUM(Sales[Sales Amount]),nextmonth('Date'[Date]))

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

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.

Top Solution Authors