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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
cho
Helper I
Helper I

Divide monthly table to a daily table

I have a table like this and this is a very small sample:

CompanyPeriod
XYZ_DE202201
XYZ_NV202202
XYZ_US202203
XYZ_CN202204
ABC_DE202201
ABC_NV202202
ABC_US202203
ABC_CN202204

 

Basically in this case, since there are 8 companies with 4 months, I need a table with row count:

(#of days in Jan + #of days in Feb + #of days in Mar + #of days in Apr) * #of companies

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @cho ,

 

To convert your table into a basic scalar output, you can follow these steps:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WioiMindxVdJRMjIwMjIwVIrVgYj5hcHEjOBiocEwMWO4mLMfTMwELObo5IxhHkgM3TyQGLp5IDEU82IB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Company = _t, Period = _t]),
    
    addPeriodStart =
    Table.AddColumn(Source, "periodStart", each
        #date(
            Number.From(Text.Start([Period], 4)),
            Number.From(Text.End([Period], 2)),
            01
        )
    ),
    addDaysInMonth = Table.AddColumn(addPeriodStart, "daysInMonth", each Date.DaysInMonth([periodStart])),
    addCustomCalc = List.Sum(addDaysInMonth[daysInMonth]) / Table.RowCount(addDaysInMonth)
in
    addCustomCalc

 

It outputs a scalar value of 30.

 

To actually expand your table into dated rows, you can follow these steps:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WioiMindxVdJRMjIwMjIwVIrVgYj5hcHEjOBiocEwMWO4mLMfTMwELObo5IxhHkgM3TyQGLp5IDEU82IB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Company = _t, Period = _t]),
    
    addPeriodStart =
    Table.AddColumn(Source, "periodStart", each
        #date(
            Number.From(Text.Start([Period], 4)),
            Number.From(Text.End([Period], 2)),
            01
        )
    ),
    addListGen = Table.AddColumn(addPeriodStart, "listGen", each List.Transform(
    {Number.From([periodStart])..Number.From(Date.EndOfMonth([periodStart]))},
    each Date.From(_)
)),
    exapndListGen = Table.ExpandListColumn(addListGen, "listGen")
in
    exapndListGen

 

Which outputs this:

BA_Pete_0-1674807211987.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
wdx223_Daniel
Super User
Super User

Source is your original table

NewStep= let a=List.Distinct(Source[Company]),b=List.Sort(List.Distinct(Source[Period])),c=List.Sum(List.Transform(b,each Date.DaysInMonth(Date.From(_&"01")))) in #table({"Company","Date"},List.TransformMany(a,each List.Dates(Date.From(b{0}&"01"),c,Duration.From(1)),(x,y)=>{x,y}))

this gives you a table with 960 rows

BA_Pete
Super User
Super User

Hi @cho ,

 

To convert your table into a basic scalar output, you can follow these steps:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WioiMindxVdJRMjIwMjIwVIrVgYj5hcHEjOBiocEwMWO4mLMfTMwELObo5IxhHkgM3TyQGLp5IDEU82IB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Company = _t, Period = _t]),
    
    addPeriodStart =
    Table.AddColumn(Source, "periodStart", each
        #date(
            Number.From(Text.Start([Period], 4)),
            Number.From(Text.End([Period], 2)),
            01
        )
    ),
    addDaysInMonth = Table.AddColumn(addPeriodStart, "daysInMonth", each Date.DaysInMonth([periodStart])),
    addCustomCalc = List.Sum(addDaysInMonth[daysInMonth]) / Table.RowCount(addDaysInMonth)
in
    addCustomCalc

 

It outputs a scalar value of 30.

 

To actually expand your table into dated rows, you can follow these steps:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WioiMindxVdJRMjIwMjIwVIrVgYj5hcHEjOBiocEwMWO4mLMfTMwELObo5IxhHkgM3TyQGLp5IDEU82IB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Company = _t, Period = _t]),
    
    addPeriodStart =
    Table.AddColumn(Source, "periodStart", each
        #date(
            Number.From(Text.Start([Period], 4)),
            Number.From(Text.End([Period], 2)),
            01
        )
    ),
    addListGen = Table.AddColumn(addPeriodStart, "listGen", each List.Transform(
    {Number.From([periodStart])..Number.From(Date.EndOfMonth([periodStart]))},
    each Date.From(_)
)),
    exapndListGen = Table.ExpandListColumn(addListGen, "listGen")
in
    exapndListGen

 

Which outputs this:

BA_Pete_0-1674807211987.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors