Forum Discussion

tonyclifton's avatar
tonyclifton
Helper III
2 years ago
Solved

Count Products over time dealing with two date fields

Hello community, I need to calculated the count of products over time (months for now, maybe with daily accuracy). I want to show the increase or decrease of products based on when they were "adde...
  • Daniel29195's avatar
    Daniel29195
    2 years ago

    tonyclifton 

     

    tried it .

    did work from my side . ( change my table to query2 , since i already have a table called exp_table)

     

     

     

    ok i think i know the problem you are encountering . 

    change the code to this : 

    count of active products per day new = 
    
    var calendar_per_product = 
    FILTER(
    GENERATE(
        all(Query2[product]),
        var pr = Query2[product]
        var createddate = SELECTCOLUMNS(FILTER(Query2,Query2[product] = pr),"createddate",Query2[createddate])
        var enddate = SELECTCOLUMNS(FILTER(Query2,Query2[product] = pr),"enddate",Query2[enddate])
        return
        CALENDAR(
            if(
                ISBLANK(createddate)  , DATEVALUE("2024-01-01"),createddate)
            ,
            if(
                ISBLANK(enddate)  , DATEVALUE("2024-12-31"),enddate)
            )
        ),
        NOT ISBLANK(Query2[product])
    )
    
    var gds = 
    GROUPBY(
        calendar_per_product,
        [Date],
        "c", countx(CURRENTGROUP() , DISTINCTCOUNT(Query2[product]))
    )
    
    var res=
    MAXX(
        FILTER(gds,[Date] in  VALUES(dimdate[Date])),
        [c])
        
        return res