How to enhance combination code with a time variable

47 views Asked by At

I found the following code by v-shex-msft I would like to use to come up with a list of combinations. Kudos to him. Now I would like to add a time variable so that only events are combined that occurred within 24 hours. Unfortunately, the filter function won't allow me to use more arguments:

Original Code:

Summary Table =

var temp= 
SUMMARIZE(
    Sheet5,
    Sheet5[Customer],
    "Combinations",CONCATENATEX(
        FILTER(
            SUMMARIZE(
                Sheet5,
                [Customer],
                Sheet5[Type]
            ),
            Sheet5[Customer] = EARLIER(Sheet5[Customer])
        ),
        [Type]&","
    )
)

return
SUMMARIZE(
    temp,
    [combinations],
    "Number",COUNTAX(
        FILTER(
            temp,
            [combinations]=EARLIER([combinations])
        ),
        [Customer]
    )
)

I tried to add the time variable as follows:

 Summary Table =

var temp = 
SUMMARIZE(
    Sheet5,
    Sheet5[Customer],
    "Combinations",CONCATENATEX(
        FILTER(
            SUMMARIZE(
                Sheet5,
                [Customer],
                Sheet5[Type], 
                Sheets5[time]
            ),
            Sheet5[Customer] = EARLIER(Sheet5[Customer]) 
            && Sheets5[time]+1 >= Earlier(Sheets5[time]) 
            && Sheets5[time]-1 <= Earlier(Sheets5[time])
        ),
        [Type]&","
    )
)

return
SUMMARIZE(
    temp,
    [combinations],
    "Number",COUNTAX(
        FILTER(
            temp,
            [combinations] = EARLIER([combinations])
        ),
        [Customer]
    )
)

Any Ideas on what is going wrong? Thank you your help is much appreciated.

1

There are 1 answers

2
mkRabbani On

Can you try this below code-

 Summary Table =

var temp = 
SUMMARIZE(
    Sheet5,
    Sheet5[Customer],
    "Combinations",CONCATENATEX(
        FILTER(
            SUMMARIZE(
                Sheet5,
                [Customer],
                Sheet5[Type], 
                Sheets5[time]
            ),
            MAX(Sheet5[Customer]) = EARLIER(Sheet5[Customer]) 
            && MAX(Sheets5[time]) +1 >= Earlier(Sheets5[time]) 
            && MAX(Sheets5[time]) -1 <= Earlier(Sheets5[time])
        ),
        [Type]&","
    )
)

return
SUMMARIZE(
    temp,
    [combinations],
    "Number",COUNTAX(
        FILTER(
            temp,
            [combinations] = EARLIER([combinations])
        ),
        [Customer]
    )
)