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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
dpotta
Resolver I
Resolver I

Help with date diff type formula

Hi

 

I am trying to write a formula in a DimDate Table, please can soomeone help with the rest of the formula!

 

The values in the table are:

 

DateMonth NameMonth Number 
01/01/2021Jan1 
01/02/2021Feb2 
01/03/2021Mar3 
01/04/2021Apr4 
01/05/2021May5 
01/06/2021Jun6 
01/07/2021Jul7 
01/08/2021Aug8 
01/09/2021Sep9 
01/10/2021Oct10 
01/11/2021Nov11 
01/12/2021Dec12 
01/01/2021Jan1 
01/02/2021Feb2 
01/03/2021Mar3 
01/04/2021Apr4 
01/05/2021May5 
01/06/2021Jun6 
01/07/2021Jul7 
01/08/2021Aug8 
01/09/2021Sep9 
01/10/2021Oct10 
01/11/2021Nov11 
01/12/2021Dec12 


I am then wanting a new column called  [Relative Month Number] where Month 1 is the Month of todays date, Month 2 is the the number of 1st of the month of the preceding date going back based on 12 months. 

 

And, in dates for preceding years the 13th month back would also be 1, 14th month back 2 etc.

 

So the table would look like this based on todays date of the 22/02/2021

 

DateMonth NameMonth NumberRel Month Number
01/01/2021Jan112
01/02/2021Feb21
01/03/2021Mar32
01/04/2021Apr43
01/05/2021May54
01/06/2021Jun65
01/07/2021Jul76
01/08/2021Aug87
01/09/2021Sep98
01/10/2021Oct109
01/11/2021Nov1110
01/12/2021Dec1211
01/01/2021Jan112
01/02/2021Feb21
01/03/2021Mar32
01/04/2021Apr43
01/05/2021May54
01/06/2021Jun65
01/07/2021Jul76
01/08/2021Aug87
01/09/2021Sep98
01/10/2021Oct109
01/11/2021Nov1110
01/12/2021Dec1211


I start off writing a variable varToday = 

 


today = Date.From(DateTime.LocalNow()),

 

And then my formula for the Rel Month Number Column begins

 

Rel Month Number

if

Date.Month([Date]) = Date.Month(varToday)

then 1

else

and then I am struggling with the rest.

 

Is this the start of a good solution, or is there a better way to look at this?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

without any if then els, letting the date.add month function do the dirty work

 

 

Table.AddColumn(#"Aggiunta colonna personalizzata", "relM1", each Date.Month(Date.AddMonths([Date],13 -Date.Month(DateTime.LocalNow()))))

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

without any if then els, letting the date.add month function do the dirty work

 

 

Table.AddColumn(#"Aggiunta colonna personalizzata", "relM1", each Date.Month(Date.AddMonths([Date],13 -Date.Month(DateTime.LocalNow()))))

 

Many thanks @Anonymous : )

Anonymous
Not applicable

 

 

Table.AddColumn(#"Modificato tipo", "relM", each let rmn=-Date.Month(DateTime.LocalNow())+[Month Number]+1 in if rmn>0 then rmn else rmn+12)

 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors