Forum Discussion

Monish2291's avatar
Monish2291
Frequent Visitor
1 year ago
Solved

I need continuous months for the project

In a table i have project, Task, Date, Month, now if a project start on jan and ends on May i should get continuous month even tho i do not have data for month, this  should get for all project and t...
  • Sachin001's avatar
    Sachin001
    1 year ago

    Monish2291 Find below if these can help:

     

    Considering we have below table as a dataset, which includes Project Name, Project Start date, Project End Date and efforts.

     

    Project Name

    Project Start Date

    Project End Date

    Efforts

    Project A

    01-01-2025

    31-05-2025

    1000

    Project B

    01-02-2025

    30-07-2025

    600

     

     

     

    In Query Editor, Create No of months between dates and Date List for program start and end date. Please refer below code:

     

    Advanced editor --> update code (M query) as below

     

    let

        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKz0pNLlHwS8xNVdKBc4NLEotKFFwSS5AFXfNSwEIKQDHXtLT8opJiBaVYHYQhjkAJA0NdIDIyMDIFcUx1jeEcQwMDAxTlTiAVRsjKzXWNDWAcM5DqWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),

        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}),

        #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),

        #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Project Name", type text}, {"Project Start Date", type date}, {"Project End Date ", type date}, {"Efforts ", Int64.Type}}),

        #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Project Start Date", "StartDate"}, {"Project End Date ", "EndDate"}}),

        #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Custom", each (Date.Year([EndDate]) - Date.Year([StartDate])) * 12 + Date.Month([EndDate]) - Date.Month([StartDate])),

        #"Added Custom1" = Table.AddColumn(#"Added Custom", "cal_Month", each [Custom] + 1),

     

        // Add a column with a list of month start dates for each row

        AddMonthList = Table.AddColumn(#"Added Custom1", "MonthStartList", each

            let

                start = Date.StartOfMonth([StartDate]),

                end = Date.StartOfMonth([EndDate]),

                count = (Date.Year(end) - Date.Year(start)) * 12 + Date.Month(end) - Date.Month(start),

                list = List.Transform({0..count}, each Date.AddMonths(start, _))

            in

                list

        ),

     

        // Expand the list into rows

        ExpandDates = Table.ExpandListColumn(AddMonthList, "MonthStartList"),

     

        // Rename the expanded column

        Final = Table.RenameColumns(ExpandDates, {{"MonthStartList", "MonthStart"}}),

        #"Added Custom2" = Table.AddColumn(Final, "Custom.1", each [#"Efforts "] / [cal_Month]),

        #"Reordered Columns" = Table.ReorderColumns(#"Added Custom2",{"Project Name", "StartDate", "EndDate", "MonthStart", "Efforts ", "Custom", "cal_Month"}),

        #"Removed Other Columns" = Table.SelectColumns(#"Reordered Columns",{"Project Name", "StartDate", "EndDate", "MonthStart", "Custom.1"})

    in

        #"Removed Other Columns"

     

     

    In result you please get result as blow:

     

     

     

     

    Save and close .

     

     

    Power BI Dashboard:

     

     

     

     

    Note - Date format is  m/d/yyyy

     

     

    Please confirm if this helps.