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

Count of weeks in a 4,5 week Month

Dear Experts,

 

Please see the below table list.I have managaed to get the Month name in the adjacent column.Hint- Week 40-43 belongs to Oct,44-47 for Nov and rest weeks with months with same logic however I'm not sure how to calculate the simple logic of count of weeks in another custom column i.e Oct should show 4 for each instanct of corresponding week i.e week 40 =4,week 41=4,week 42=4,week 43=4 ,likewise Dec should show 5 as it has 5 weeks

 

Thanks in advance.

Week- Month

Week 40 FY22
Week 41 FY22
Week 42 FY22
Week 43 FY22
Oct 22
Week 44 FY22
Week 45 FY22
Week 46 FY22
Week 47 FY22
Nov 22
Week 48 FY22
Week 49 FY22
Week 50 FY22
Week 51 FY22
Week 52 FY22
Dec 22

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Week- Month", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Start([#"Week- Month"],4)="Week" then null else DateTime.FromText([#"Week- Month"]), type date),
    #"Filled Up" = Table.FillUp(#"Added Custom",{"Custom"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Up", each Text.StartsWith([#"Week- Month"], "Week")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Custom"}, {{"GroupTables", each _, type table [#"Week- Month"=nullable text, Custom=date]}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "CountRows", each Table.RowCount([GroupTables])),
    #"Expanded GroupTables" = Table.ExpandTableColumn(#"Added Custom1", "GroupTables", {"Week- Month"}, {"Week- Month"})
in
    #"Expanded GroupTables"

Hope this helps.

Untitled.png

 

Untitled1.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Week- Month", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Start([#"Week- Month"],4)="Week" then null else DateTime.FromText([#"Week- Month"]), type date),
    #"Filled Up" = Table.FillUp(#"Added Custom",{"Custom"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Up", each Text.StartsWith([#"Week- Month"], "Week")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Custom"}, {{"GroupTables", each _, type table [#"Week- Month"=nullable text, Custom=date]}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "CountRows", each Table.RowCount([GroupTables])),
    #"Expanded GroupTables" = Table.ExpandTableColumn(#"Added Custom1", "GroupTables", {"Week- Month"}, {"Week- Month"})
in
    #"Expanded GroupTables"

Hope this helps.

Untitled.png

 

Untitled1.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thanks a lot however month is in text format not date i.e Oct,Nov in my raw data - do you think it will still work?

Try it.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

It worked thanks a lot..

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

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.