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 sam...
  • Daniel29195's avatar
    2 years ago

    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! 🤠