Forum Discussion
Count Products over time dealing with two date fields
- 2 years ago
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
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
Thank you very much. It works now with the sample data.
Before I'll try to put this in my real data report can you tell me how to deal with adding slicers that affect the calculation?
For example, with the sample data, if I use CreatedDate as a slicer or have another column like "plant" it will always output a different calculation for each month - compared to not being filtered at all.
Any ideas how to deal with that?
Thank you.
- Daniel291952 years agoCommunity Champion
for date, you should filter from dimdate and not createddate .
because the code works base on the dimdate .
- tonyclifton2 years agoHelper III
I agree with dimdate but what about filtering by other columns of the original table like Plant for example?
- Daniel291952 years agoCommunity Champion
i cant tell, since i dont have an idea how the model is structured.
but i assume it should work, if you have plant column that already filters the data .