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

Month number

Hi everyone. I need to do some odd time transformation for my DateDim table in Power BI.

My DateDim is custom table.
Week start date is on Saturday.
For the last week of the month, if it has dates fall in two month (like this case 12/28/2019->1/3/2020), the month number of every day in that week is the next month.

In this screenshot, Month number of 12/28, 12/29, 12/30, 12/31 is 1 not 12.

I understand the logic behind it, but cant replicate from the original excel file to Power BI.

1st photo: the desired Date table in PowerBI, I got everything except Correct Month Number.
2nd photo: the shot from orig excel File which you can see the logic.

 
 

Capture.PNGCapture2.PNG

1 ACCEPTED SOLUTION

I found the solution that I need from another Thread

 

https://community.powerbi.com/t5/Desktop/Custom-Fiscal-Year-Calendar/td-p/85228

 

I will close this topic

 

View solution in original post

8 REPLIES 8
v-kelly-msft
Community Support
Community Support

Hi @clairetran0426

 

You need a calculated column as below:

 

Correct Month number = 
var a = MONTH('Table'[Week Start on Sat ])
Return
SWITCH(TRUE(), a in {1,3,5,7,8,10,12} && 'Table'[Date].[Day]>25 && 31-'Table'[Date].[Day]+'Table'[Column]<7,1,
a in {4,6,9,11} && 'Table'[Date].[Day]>24 && 30-'Table'[Date].[Day]+'Table'[Column]<7,1,
a =2 && MOD(YEAR('Table'[Week Start on Sat ]),4)=0 &&'Table'[Date].[Day]>23 && 29-'Table'[Date].[Day]+'Table'[Column]<7,1,
a=2 && MOD(YEAR('Table'[Week Start on Sat ]),4)<>0 &&'Table'[Date].[Day]>22 && 28-'Table'[Date].[Day]+'Table'[Column]<7,1,
'Table'[Month Number]
)

 

And you will see :

 

Annotation 2020-01-31 120536.png

 

For the related .pbix file,pls click here.

 

 
Best Regards,
Kelly

Hi @v-kelly-msft;

Your solution works but only for Dec. Is there a way to make it dynamic, work for all 12 months?

 

 

Capture3.PNG

 
 

Hi @clairetran0426

 

You said "For the last week of the month, if it has dates fall in two month (like this case 12/28/2019->1/3/2020), the month number of every day in that week is the next month." so every last days for a month,if it starts and ends in 2 different months,it should be calculated in 1 ,right?

So here,if you put 2019/11/30 to the table,it works fine.

Annotation 2020-02-03 151921.png

 

Best Regards,
Kelly

@v-kelly-msft 

No. for Nov 30th 2019, the correct month is 12. It is not always 1 for correct Month.

 

I just firgured out the logic for month number for this project is 5/4/4

Jan has 5 weeks

Feb has 4 weeks

March has 4 weeks

April has 5 weeks

May has 4 weeks

June has 4 weeks

July has 5 weeks

August has 4 weeks

Sep has 4 weeks

Oct has 5 weeks

Nov has 4 weeks

Dec has 4 weeks

 

In addition to that rule, the start day of week is on Sat. So in the senerio below, the 1st week of January is start on Start 12/28/2019 -> 1/3/2019.

 

The pic show the logic:

So 

Capture2.PNG

I found the solution that I need from another Thread

 

https://community.powerbi.com/t5/Desktop/Custom-Fiscal-Year-Calendar/td-p/85228

 

I will close this topic

 

Hi,
How can i calculate previous month data?

aqil1995_0-1639562920080.png

for example i selected febuary data and i want to show feb data and january data.

aqil1995_1-1639563052352.png
min of tower value = month selected (Feb 2020)
Tower Previous = month before (jan 2020)

but i cant find a way to display the previous month data.

MFelix
Super User
Super User

Hi  @clairetran0426 ,:

 

On the query editor try the following code for a calculated column:

 

Date.Month(Date.StartOfWeek([Date],6) +#duration(7,0,0,0))

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



@MFelix I didnt use query editor. It is a custome Date table

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.