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
Anonymous
Not applicable

How to get custom month and week in the report?

Hi All,

 

I have a report where we are showing count of invoices per month in the report and the way we are calculating the month is basically month of posting date. However, I want my month to be calculated from last Tuesday of previous month to the last Tuesday of current month of posting date.

 

Similarly when calculating count of invoices per week, I want to calculate from Tuesday to Tuesday of posting date.

 

Does anyone has a clue how to do it?

 

Thanks in advance!

1 ACCEPTED SOLUTION
9 REPLIES 9
Anonymous
Not applicable

Thanks Amit!

 

I tried the solution provided by you and I am facing one more issue. The date in my table is basically a date hierarchy with year, quarter,month and day.  How do I use the queries provided in your blog in this case?

Hi @Anonymous 

You can add a Date column by combining these date hierarchy columns and change this new column to Date type. Then you can use Date column in Amit's codes. For example,

In Query Editor with M:

Add a custom column: = #date([Year], [Month], [Day])

030201.jpg

 

Or In PBI Desktop with DAX:

Add a calculated column: DATE([Year],[Month],[Day])

030202.jpg

 

Regards,
Community Support Team _ Jing Zhang
If this post helps, please Accept it as the solution to help other members find it.

Anonymous
Not applicable

Hi, 

Thanks!

I have already done for weeks now. Dop you know how to do it for the month?

 

Regards

Pranati

@Anonymous 

Assume you already have Weekday (Tue-Mon) column in Date table, you can try below codes to add custom month columns.

Month Start date = 
var _lastTuesdayThisMonth = MAXX(FILTER('Date','Date'[Weekday]=1 && 'Date'[Date]<=EOMONTH(EARLIER('Date'[Date]),0)),'Date'[Date])
return
IF('Date'[Date]<_lastTuesdayThisMonth,MAXX(FILTER('Date','Date'[Weekday]=1 && 'Date'[Date]<=EOMONTH(EARLIER('Date'[Date]),-1)),'Date'[Date]),_lastTuesdayThisMonth)
Month End date = 
var _lastTuesdayThisMonth = MAXX(FILTER('Date','Date'[Weekday]=1 && 'Date'[Date]<=EOMONTH(EARLIER('Date'[Date]),0)),'Date'[Date])
return
IF('Date'[Date]<_lastTuesdayThisMonth,_lastTuesdayThisMonth-1,MAXX(FILTER('Date','Date'[Weekday]=1 && 'Date'[Date]<=EOMONTH(EARLIER('Date'[Date]),1)),'Date'[Date])-1)
MonthDay = DATEDIFF([Month Start date],[Date],DAY)+1
Month of Year = 
var _lastTuesdayThisMonth = MAXX(FILTER('Date','Date'[Weekday]=1 && 'Date'[Date]<=EOMONTH(EARLIER('Date'[Date]),0)),'Date'[Date])
var _thisCalendarMonth = MONTH('Date'[Date])
return
IF(_thisCalendarMonth<12,IF('Date'[Date]<_lastTuesdayThisMonth,_thisCalendarMonth,_thisCalendarMonth+1),IF('Date'[Date]<_lastTuesdayThisMonth,_thisCalendarMonth,1))

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

Anonymous
Not applicable

@v-jingzhang Your solution in working in a very weird way for Date 10th March 2021 it is giving month start date as 10th March 2021 and month end date as 9th March 2021. However, month start date should be 24th Feb 2021(Last wednesday of previous month of date) and month end date should be 30th March 2021 (Last tuesday of month of date).

 

Do you have a clue how to do it?

Anonymous
Not applicable

Hi,

 

I am trying the below query:

Month End date =
var _lastWednesdayThisMonth = MAXX(FILTER(ArrearBalanceDetail,ArrearBalanceDetail[Weekday(Wed-Tue)]=1 && ArrearBalanceDetail[PostingDate_Para]<=EOMONTH(EARLIER(ArrearBalanceDetail[PostingDate_Para]),0)),ArrearBalanceDetail[PostingDate_Para])
return
IF(ArrearBalanceDetail[PostingDate_Para]<_lastWednesdayThisMonth,_lastWednesdayThisMonth-1,MAXX(FILTER(ArrearBalanceDetail,ArrearBalanceDetail[Weekday(Wed-Tue)]=1 && ArrearBalanceDetail[PostingDate_Para]<=EOMONTH(EARLIER(ArrearBalanceDetail[PostingDate_Para]),1)),ArrearBalanceDetail[PostingDate_Para])-1)

 

I am facing one issue here. For current month it is giving me month end date as 9th March 2021 since it is the last tuesday till now. But it should be the last tuesday of this month which is 30th March 2021 even if there is no data for it.

Anonymous
Not applicable

Thanks Jing!

 

This is working. However, I want month of the year to also have year element, beacuse I have filters for the year in my report. Is that possible?

 

Not sure what is the format you want, I create below columns based on previous columns. 

Fiscal Year = YEAR('Date'[Month End date])
New Month of Year = 'Date'[Fiscal Year]*100+'Date'[Month of Year]

 

Jing

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.