group-bydaxsummarize

DAX concatenate list of a column value (ex. contract) grouped by date


I'm trying to create a list of contracts that expire by dates. I looked on the many sites for a solution.

I have a measure that calculates the date and i need calculated table with a summurazed version.

I have been able to create the middle step, that is the list of contracts by date. And I can't get to the last steps that is one line per date with a concatenate list of the contracts.

step one : 1 line per contract to renew

this is the dax code for the mid step table

Table contracts by date = 

VAR T1 = 
CALCULATETABLE(
    SUMMARIZE(contracts,
       contracts[Contrat], 
       contracts[Mandat], 
       contracts[CléContratDemande], 
       "date",[_mesure_date_expire], 
       "fullKey", contracts[CléContratDemande]
    ),
    contracts[Statut] = "Active",
    ALLEXCEPT(contracts, contracts[Contrat],contracts[Mandat])
)

RETURN 
t1

[_mesure_date_expire] is a measure outside of the table that calculate the expiration date.

This is the result of the mid step table:

mid table

Wanted result

The result i'm trying to achieve is this :

expected final table

the column contracts is the concatenation of the column fullkey of the mid table step.

you see that april 11th has 2 contracts on the same line

I tried to create a var for the second table with different combinations of VALUES, SUMMARIZE, GROUPBY, CONCATENATE, CONCATENATEX without success.

Help and input will be appreciated.

Thanks

Pat


Solution

  • You can achieve this using SUMMARIZE to group by date, and CONCATENATEX to concatenate the fullKey values.

    Final Table = 
    VAR MidStep = 
        CALCULATETABLE(
            SUMMARIZE(
                contracts,
                contracts[Contrat], 
                contracts[Mandat], 
                contracts[CléContratDemande], 
                "date", [_mesure_date_expire], 
                "fullKey", contracts[CléContratDemande]
            ),
            contracts[Statut] = "Active",
            ALLEXCEPT(contracts, contracts[Contrat], contracts[Mandat])
        )
    
    RETURN
        ADDCOLUMNS(
            SUMMARIZE(MidStep, [date]),
            "Contracts", 
            CALCULATE(
                CONCATENATEX(
                    VALUES(FILTER(MidStep, [date] = EARLIER([date]))[fullKey]), 
                    [fullKey],
                    ", "
                ) //Unique Values
            )
        )