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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
esam
Frequent Visitor

Month Series

Hi I have date table from 2023 to 2025 i want a column with month series where 36 being december 2025 and 1 being January 2023.

1 ACCEPTED SOLUTION

hi @esam 

t

Aha, try like

Month Series =

DATEDIFF(DATE(2023, 1, 1), [Date], MONTH)+1

View solution in original post

11 REPLIES 11
smpa01
Super User
Super User

@esam not sure what your Date table looks like, I simply Assumed that you have only 1 column table as Calendar[Date]

 

 

Column =
RANKX (
    'Calendar',
    DATE ( MONTH ( 'Calendar'[Date] ), YEAR ( 'Calendra'[Date] ), 1 ),
    ,
    ASC,
    DENSE
)

 

 

smpa01_0-1675798450010.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
FreemanZ
Super User
Super User

hi @esam 

try to add a column like:

Month Series =

DATEDIFF([Date], DATE(2023, 1, 1), MONTH)+1

esam
Frequent Visitor

Hi @FreemanZ 

The solution you provided gave something similar but not accurate it is giving me result in negative 

for jan 2023 it is one than feb 2023 0 and for december 2025 -33 

hi @esam 

t

Aha, try like

Month Series =

DATEDIFF(DATE(2023, 1, 1), [Date], MONTH)+1

esam
Frequent Visitor

Thank you for the solution @FreemanZ can you explain a bit how this logic is working here !! 

also how to get better with dax with real world scenarios 

hi @esam 

 

there is no secret, as long as you know the DATEDIFF function, which returns the number of periods between two dates. In this case, the period is MONTH. 

 

In general,  learning DAX by doing. Try to bring change and value to your daily work with DAX.  If time allows, come back to the community and try to contribute. 

johnt75
Super User
Super User

You could try a calculated column like

Month series =
VAR ReferenceDate = 'Date'[Date]
VAR PrevMonths =
    CALCULATETABLE (
        VALUES ( 'Date'[Year month] ),
        REMOVEFILTERS ( 'Date' ),
        'Date'[Date] < ReferenceDate
    )
RETURN
    COUNTROWS ( PrevMonths ) + 1
esam
Frequent Visitor

Removefilter with comparison operator is not correct 

I think maybe you've missed a close bracket, the REMOVEFILTERS and comparison are separate.

esam
Frequent Visitor

image.jpg

the series generated by this 13,12,....1

OK, the below works for me

Month series = 
VAR ReferenceDate = 'Date'[Date]
VAR PrevMonths =
    CALCULATETABLE (
        DISTINCT ( 'Date'[Year month] ),
        REMOVEFILTERS ( 'Date' ),
        'Date'[Date] <= ReferenceDate
    )
RETURN
    COUNTROWS ( PrevMonths ) 

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.

Top Kudoed Authors