Forum Discussion

HankScorpio2's avatar
HankScorpio2
Helper I
11 months ago
Solved

Create New Column with True False outcome based on date and id

Hi 

 

I have a few years worth of consultant metric data. I want to create a custom column that is based on the lowest date of the first occurrence of a consultant id and mark New in the column for the first 10 weeks. And for all other dates past that occurrence for that id mark No. 

 

Something like this but for every id across all the years. From the first date the id occurs until 7 weeks later. I tried it in excel but it only does it for the first 70 days and ignores all new ids after that time. 

 

=LET(AgentStartDate, MIN(FILTER([Interval Start], [Agent Id] =[Agent Id])), IF([@[Interval Start]] <= AgentStartDate + 70, "New", "No"))

 

Interval StartAgent IdAnsweredTotal HandleTotal TalkTotal HoldTotal ACWNew Starter
13/05/20219c9f586a-ca35-4445-acfb-27f54bea5b0159421955942219111153400000New
14/05/20219c9f586a-ca35-4445-acfb-27f54bea5b0178350234351966814285273403000New
17/05/20219c9f586a-ca35-4445-acfb-27f54bea5b011920776445779616265482966435000New
18/05/20219c9f586a-ca35-4445-acfb-27f54bea5b012018153014899091738301065335000New
19/05/20219c9f586a-ca35-4445-acfb-27f54bea5b013220314041845787348936046967000New
20/05/20219c9f586a-ca35-4445-acfb-27f54bea5b0129223767361173281934339967216000New
21/05/20219c9f586a-ca35-4445-acfb-27f54bea5b012818093604783743339395166320000New
24/05/20219c9f586a-ca35-4445-acfb-27f54bea5b0135230296791117950743606757495000New
26/05/20219c9f586a-ca35-4445-acfb-27f54bea5b012719802255863521433586657812000New
27/05/20219c9f586a-ca35-4445-acfb-27f54bea5b012716110715779181528813835443000New
28/05/20219c9f586a-ca35-4445-acfb-27f54bea5b012517046237795542839695235126000New
31/05/20219c9f586a-ca35-4445-acfb-27f54bea5b012413956113593930923867765631000New
2/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b012016275640644173658061124030000New
12/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b012113127777521983934755074436000New
13/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b012115663483698796136394965040000New
14/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b012111925114470295532210294003000New
15/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b01324822111155997538214788000New
16/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b01146793727418914874845000New
19/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b015351950510530488857361581000New
21/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b0196581368333642519817541264000New
22/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b012212216844605865132879042873000New
23/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b012416827237886092429222795047000No
26/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b012517377667868152041313024568000No
27/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b011612937312518244446088063147000No
28/07/2021 0:009c9f586a-ca35-4445-acfb-27f54bea5b01422772631188650472865616000No
  • M Code:

    NewStep=let a=Table.Group(YourSourceName,"Agent Id",{"MinDate",each List.Min([Interval Start])}) in Table.AddColumn(YourSourceName,"New Starter", each if [Interval Start]<=a{[#"Agent Id"=[Agent Id]]}[Interval Start]+#duration(70,0,0,0) then "New" else "No")

     

    DAX Code:

    NewCalculatedColumn=VAR _mindate=CALCULATE(MIN(YourTable[Interval Start]),ALLEXCEPT(YourTable,YourTable[Agent Id])) RETURN IF(YourTable[Interval Start]<=_mindate+70,"New","No")

3 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Community Champion

    M Code:

    NewStep=let a=Table.Group(YourSourceName,"Agent Id",{"MinDate",each List.Min([Interval Start])}) in Table.AddColumn(YourSourceName,"New Starter", each if [Interval Start]<=a{[#"Agent Id"=[Agent Id]]}[Interval Start]+#duration(70,0,0,0) then "New" else "No")

     

    DAX Code:

    NewCalculatedColumn=VAR _mindate=CALCULATE(MIN(YourTable[Interval Start]),ALLEXCEPT(YourTable,YourTable[Agent Id])) RETURN IF(YourTable[Interval Start]<=_mindate+70,"New","No")

  • You seem to be mixing M and DAX code. Please specify if you want this column to be added in Power Query or in Power BI