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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
JeevanMallya
Helper I
Helper I

Missing Week Numbers

I have 3 Columns - First Column is YEAR in format YYYY of Type WholeNumber, Second column is WEEK_NUM in format WW of Type WHole Number Ranging from 0 to 53, Third Column is Result of some data. 

The Problem : Some weeks are missing for respective years highlighted in Red in the attached screenshot.

I want to identify those missing weeks and insert the running week number, Year and insert zero in the third column.

Could you please help me with the steps or Powerbi query.

 

JeevanMallya_0-1705149171546.png

 

2 ACCEPTED SOLUTIONS
AlienSx
Super User
Super User

let
    Source = your_3_columns,
    fifty_three = List.Buffer({0..53}),
    f = (tbl) =>
        [a = tbl & Table.FromColumns({List.Difference(fifty_three, tbl[WEEK_NUM])}, {"WEEK_NUM"}),
        b = Table.Sort(a, "WEEK_NUM"),
        c = Table.TransformColumns(b, {"CREATED_COUNT", each _ ?? 0})][c],
    g = Table.Group(Source, "YEAR", {"tbl", f}),
    exp = Table.ExpandTableColumn(g, "tbl", {"WEEK_NUM", "CREATED_COUNT"})
in
    exp

View solution in original post

Can you please help me how to build this step wise please.

View solution in original post

5 REPLIES 5
Fowmy
Super User
Super User

@JeevanMallya 

Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc7LDQAhCEXRXli7QBQ/tRj7b2N4GjOwIfEEzF2LhEUoUVUbc9JOPzXQCNTvqqdhQ+LWtNHZkzIofK8ZFA71XMfDgoj2CC8JDZCzU70gvbCXfvOdIFyDoDtb0f4A", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, #"Week Num" = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Week Num", Int64.Type}, {"Value", Int64.Type}}),
    Table = #"Changed Type",

    __t1 = 
    Table.ExpandListColumn(
        Table.AddColumn( 
            Table.FromColumns( {{List.Min(Table[Year]),List.Max(Table[Year]) }}, {"Years"} ),
            "Weeks",  
            each {1..53},  type number 
        ),
        "Weeks"
    ),
    
    __t2 =  
    Table.ReplaceValue( 
        Table.ExpandTableColumn( 
            Table.NestedJoin(__t1, {"Weeks","Years"}, Table, {"Week Num","Year"}, "Custom1", JoinKind.LeftOuter),"Custom1", {"Value"}, {"Value"}
        ),
        null,0,Replacer.ReplaceValue,{"Value"}
    )
in

 


Orginal Table:

Fowmy_0-1705162990421.png


Result:

Fowmy_1-1705163008410.png

 

 




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

I have a query.

Here for the missing weeks, Value should be zero but in the result i see some values are added.

Like for 2022 , Weeks 1 to 44 should be zero.

@JeevanMallya 

I forgot to add the year, now it's fixed please refer my orginal reply.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

AlienSx
Super User
Super User

let
    Source = your_3_columns,
    fifty_three = List.Buffer({0..53}),
    f = (tbl) =>
        [a = tbl & Table.FromColumns({List.Difference(fifty_three, tbl[WEEK_NUM])}, {"WEEK_NUM"}),
        b = Table.Sort(a, "WEEK_NUM"),
        c = Table.TransformColumns(b, {"CREATED_COUNT", each _ ?? 0})][c],
    g = Table.Group(Source, "YEAR", {"tbl", f}),
    exp = Table.ExpandTableColumn(g, "tbl", {"WEEK_NUM", "CREATED_COUNT"})
in
    exp

Can you please help me how to build this step wise please.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors