Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
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.
Solved! Go to Solution.
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.
@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:
Result:
⭕ 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.
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
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.
User | Count |
---|---|
25 | |
10 | |
9 | |
9 | |
8 |