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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. 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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.