cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
v_mark
Helper IV
Helper IV

Date Table Month Number 1-36

Once we have a date table. Normally when we do Month(date) it will give us numbers from 1 -12

Is there a way to make that continuous/extend like 1-36?

1 ACCEPTED SOLUTION
mahoneypat
Microsoft
Microsoft

I use this formula to add a custom colum in the query editor that calculates the months from the current month.  You still get a month index but the zero value is the current month, which is useful in visual level filters to have a dynamic filter (e.g., also show the latest 6 months).

 

let
today = Date.From(DateTime.LocalNow()),
thisdate = [Date]
in
(12 * Date.Year(thisdate) + Date.Month(thisdate)) - (12 * Date.Year(today) + Date.Month(today))

 

You can adapt it to get your request with the following.  Replace Previous Step with your actual previous step name in the query editor (#"Changed Type", etc.).

 

let
firstdate = List.Min(#"Previous Step"[Date]),
thisdate = [Date]
in
(12 * Date.Year(thisdate) + Date.Month(thisdate)) - (12 * Date.Year(firstdate) + Date.Month(firstdate))

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Microsoft
Microsoft

I use this formula to add a custom colum in the query editor that calculates the months from the current month.  You still get a month index but the zero value is the current month, which is useful in visual level filters to have a dynamic filter (e.g., also show the latest 6 months).

 

let
today = Date.From(DateTime.LocalNow()),
thisdate = [Date]
in
(12 * Date.Year(thisdate) + Date.Month(thisdate)) - (12 * Date.Year(today) + Date.Month(today))

 

You can adapt it to get your request with the following.  Replace Previous Step with your actual previous step name in the query editor (#"Changed Type", etc.).

 

let
firstdate = List.Min(#"Previous Step"[Date]),
thisdate = [Date]
in
(12 * Date.Year(thisdate) + Date.Month(thisdate)) - (12 * Date.Year(firstdate) + Date.Month(firstdate))

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


JW_van_Holst
Resolver III
Resolver III

Assuming you have the Date column sorted ascending:

Add column with formula: (Year(date) - Year("#LatestQueryStep"{0}[date}) * 12 + Month(date)

//JW

Tried to add this as a custom column getting an error

 

v_mark_0-1618342493217.png

 

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors