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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
JeevanMallya
Resolver II
Resolver II

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.