Forum Discussion

Anonymus_18's avatar
Anonymus_18
Frequent Visitor
2 years ago
Solved

Create a new column for missing months with existing data

I have a data in which it'll only be for 4 months i need to reprint that values in the new column.for an example i have data in april'23 i nned to print the data for dec'22 to marc'23 . I have an sample I have provide two table Table 1 and 2. Table one is the i have and table is the desired output.

table 1  
datevalue
Apr-225
Jun-227
Oct-224
Dec-223
Apr-232
Jun-238
Oct-239
Dec-237
table 2 
datevalue
Dec-215
Jan-225
Feb-225
Mar-225
Apr-227
May-227
Jun-224
Jul-224
Aug-224
Sep-224
Oct-223
Nov-223
Dec-222
Jan-232
Feb-232
Mar-232
Apr-238
May-238
Jun-239
Jul-239
Aug-239
Sep-239
Oct-237
Nov-237
Dec-23 
  • Hello Anonymus_18 

    output : 

     

     

    steps : 

    step  1 : 
    adding 2 columns to original table : 

    COLUMN1 

    Column = 
    SELECTCOLUMNS(
    OFFSET(
        1, 
        SUMMARIZE(
            date_sol,
            date_sol[date],
            date_sol[value]
        ),
        ORDERBY(date_sol[date], asc)
    ),
    date_sol[value]
    )

     

    COLUMN2

    next ddate = 
    var t = 
    SELECTCOLUMNS(
    OFFSET(
        1, 
        SUMMARIZE(
            date_sol,
            date_sol[date],
            date_sol[value]
        ),
        ORDERBY(date_sol[date], asc)
    ),
    date_sol[date]
    )
    return
    t

     

     

    step2 : 

    create the table : 

    Table_new = 
    var datasource = 
    FILTER(
    SELECTCOLUMNS(
        date_sol,
        "date1",date_sol[date],
        "value", date_sol[value],
        "new_value",date_sol[Column],
        "nextdate", edate(date_sol[next ddate],-1)
    ),
    not isblank([nextdate]) 
    )
    
    
    var added_row = 
    DATATABLE(
        "date1" , DATETIME,
        "value", INTEGER,
        "new_value", INTEGER,
        "nextdate", DATETIME,
        {
            {"2021-12-01",0,5, "2022-03-01"}
    
        }
    )
    
    
    var full_table = 
    UNION(
        added_row,
        datasource
    )
    
    
    var res = 
    SELECTCOLUMNS(
    GENERATE(
        full_table,
        var d1  = [date1]
        var d2 =  [nextdate]
        return
        CALENDAR(d1,d2)
        
        ),
    
        "newvalue",[new_value],
        "dategenerated",[Date]
    )
        
            
           
    return 
    FILTER(
        res,
        DAY([dategenerated]) = 1
    )

     

     

    you can modify, the code as per your convenience.

     

     

     

    If my answer helped sort things out for you, i would appreciate a thumbs up πŸ‘ and mark it as the solution !βœ…
    It makes a difference and might help someone else too. Thanks for spreading the good vibes! πŸ€ 

     

1 Reply

  • Daniel29195's avatar
    Daniel29195
    Community Champion

    Hello Anonymus_18 

    output : 

     

     

    steps : 

    step  1 : 
    adding 2 columns to original table : 

    COLUMN1 

    Column = 
    SELECTCOLUMNS(
    OFFSET(
        1, 
        SUMMARIZE(
            date_sol,
            date_sol[date],
            date_sol[value]
        ),
        ORDERBY(date_sol[date], asc)
    ),
    date_sol[value]
    )

     

    COLUMN2

    next ddate = 
    var t = 
    SELECTCOLUMNS(
    OFFSET(
        1, 
        SUMMARIZE(
            date_sol,
            date_sol[date],
            date_sol[value]
        ),
        ORDERBY(date_sol[date], asc)
    ),
    date_sol[date]
    )
    return
    t

     

     

    step2 : 

    create the table : 

    Table_new = 
    var datasource = 
    FILTER(
    SELECTCOLUMNS(
        date_sol,
        "date1",date_sol[date],
        "value", date_sol[value],
        "new_value",date_sol[Column],
        "nextdate", edate(date_sol[next ddate],-1)
    ),
    not isblank([nextdate]) 
    )
    
    
    var added_row = 
    DATATABLE(
        "date1" , DATETIME,
        "value", INTEGER,
        "new_value", INTEGER,
        "nextdate", DATETIME,
        {
            {"2021-12-01",0,5, "2022-03-01"}
    
        }
    )
    
    
    var full_table = 
    UNION(
        added_row,
        datasource
    )
    
    
    var res = 
    SELECTCOLUMNS(
    GENERATE(
        full_table,
        var d1  = [date1]
        var d2 =  [nextdate]
        return
        CALENDAR(d1,d2)
        
        ),
    
        "newvalue",[new_value],
        "dategenerated",[Date]
    )
        
            
           
    return 
    FILTER(
        res,
        DAY([dategenerated]) = 1
    )

     

     

    you can modify, the code as per your convenience.

     

     

     

    If my answer helped sort things out for you, i would appreciate a thumbs up πŸ‘ and mark it as the solution !βœ…
    It makes a difference and might help someone else too. Thanks for spreading the good vibes! πŸ€