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
veer
Frequent Visitor

How to Assign Month Number Dynamically

Assign Month Number Dynamically  

Example =

feb=1  

mar=2

april=3

.

.

.

dec=11

current month jan is =12

 

Last 12 month data show 

Moving AvG Prob

          

cureent month is jan =12Screenshot (38).png

1 ACCEPTED SOLUTION
zoloturu
Memorable Member
Memorable Member

@veer,

 

Please create calculated column in your table with formula below:

 

 

DynamicMonth = IF(MOD(MONTH(Table1[CreatedDate]) - MONTH(TODAY())+12,12)=0,12,MOD(MONTH(Table1[CreatedDate]) - MONTH(TODAY())+12,12))

Dynamic month in DAXDynamic month in DAX

 

Where Table1 = your table name,

[CreatedDate] = your date field name.

 

Let me know if I understood you correct.

View solution in original post

7 REPLIES 7
zoloturu
Memorable Member
Memorable Member

@veer,

 

What do you mean under dynamically here?

 

I see that you just made offset. Do you mean each time Feb = 1, .., Apr = 3 etc.? And it would be for now, January and the same would be for next months like every time Feb = 1, .., Apr = 3 etc?

 

Or in February you should have Mar = 1,..,May=3, etc?

 

Where do you plant to user this month number? Or just to sort chart you've shown?

veer
Frequent Visitor

@zoloturucurrent month is -Jan  ..so i want current month number is 12 

current, jan  12,
        _current - 1, 11,
        _current - 2, 10,
        _current - 3, 9,
        _current - 4, 8,
        _current - 5, 7,
        _current - 6, 6,
        _current - 7, 5,
        _current - 8, 4,
        _current - 9, 3,
        _current - 10, 2,
        _current - 11, 1,
        

this type logic i want ..in dax  

zoloturu
Memorable Member
Memorable Member

@veer,

 

Please create calculated column in your table with formula below:

 

 

DynamicMonth = IF(MOD(MONTH(Table1[CreatedDate]) - MONTH(TODAY())+12,12)=0,12,MOD(MONTH(Table1[CreatedDate]) - MONTH(TODAY())+12,12))

Dynamic month in DAXDynamic month in DAX

 

Where Table1 = your table name,

[CreatedDate] = your date field name.

 

Let me know if I understood you correct.

veer
Frequent Visitor

@zoloturuThanksMan Happy

vanessafvg
Super User
Super User

@veer best thing to do is have a calendar table where you create a column called month number where you can assign with an if statement, alternatively you can use switch statement to create a  calculated column, or you could also create a if statement in power query (m)

 

month no = switch(month, 

 "feb", 1,

"mar",2 etc)

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




@vanessafvg I want dynamic month number .

I'm sorry if I'm missing the point, but can't you just use a relative date filter to always give you the last 12 months?

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.