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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Can we calculate Today's week number - number from Text.Middle M code ?

Hi,

 

I'm getting week number with M code(Text.Middle([Source Name],1,2)) from 'Source Name' column which will be 11.

 

If today's week number is 35 then hope to calculate Today's week number(variable) - 'Source Name' week number which will be 24.

I don't need all period of data source so that I can filter the data source only in the past 26 weeks(half year) with this calculations using filter 'Less than 26'.

 

jeongkim_0-1724805336262.png

 

 

2 ACCEPTED SOLUTIONS
rajendraongole1
Super User
Super User

Hi @Anonymous calculate the current week number as below

rajendraongole1_0-1724814821470.png

 

use the add column >> custom column in query editor, 

Date.WeekOfYear(DateTime.LocalNow())

 

output you will get 35 current weeknumber

 

create one more new column to find the difference 

rajendraongole1_1-1724814913109.png

 

Now, Filters the data to include only records from the past 26 weeks

rajendraongole1_2-1724814959448.png

 

 

Hope this works





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

Proud to be a Super User!





View solution in original post

Hi @Anonymous -yes , we can combine the calculation into a single custom column without creating separate steps

 

rajendraongole1_0-1724815878689.png

 

AddWeekDifference = Table.AddColumn(
Source,
"Week Difference",
each Date.WeekOfYear(DateTime.LocalNow()) - Number.FromText(Text.Middle([Source Name], 2, 2)),
Int64.Type

 

Hope this helps.





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

Proud to be a Super User!





View solution in original post

5 REPLIES 5
rajendraongole1
Super User
Super User

Hi @Anonymous calculate the current week number as below

rajendraongole1_0-1724814821470.png

 

use the add column >> custom column in query editor, 

Date.WeekOfYear(DateTime.LocalNow())

 

output you will get 35 current weeknumber

 

create one more new column to find the difference 

rajendraongole1_1-1724814913109.png

 

Now, Filters the data to include only records from the past 26 weeks

rajendraongole1_2-1724814959448.png

 

 

Hope this works





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

Proud to be a Super User!





Anonymous
Not applicable

Hi 

Thanks for your support.

Can we combine them in 1 M code at 1 column?

 

e.g. Week Difference = Date.WeekOfYear(DateTime.LocalNow()) - Text.Middle([Source Name],1,2) 

without creating seperate custom columns?

 

Hi @Anonymous -yes , we can combine the calculation into a single custom column without creating separate steps

 

rajendraongole1_0-1724815878689.png

 

AddWeekDifference = Table.AddColumn(
Source,
"Week Difference",
each Date.WeekOfYear(DateTime.LocalNow()) - Number.FromText(Text.Middle([Source Name], 2, 2)),
Int64.Type

 

Hope this helps.





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

Proud to be a Super User!





Anonymous
Not applicable

Can you see what was wrong from my end? 

 

jeongkim_0-1724824997456.png

 

Anonymous
Not applicable

resolved thanks

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors