Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Group by / Summarize with 'incomplete' data?

Hi Power BI Community,

 

I've got an interesting problem that perhaps you can shed some light on.

 

Please consider the below two tables:

 

DocumentIDDocument
1DocA
2DocB
3DocC

 

PersonIDDocumentIDDate_Added
1101/01/2018
1226/02/2018
2113/03/2018
3321/09/2018

 

What I'm looking for is all DocumentIDs to be returned with either the Date_Added or blank per PersonID. For example:

 

PersonIDDocumentIDDate_Added
1101/01/2018
1226/02/2018
13 
2113/03/2018
22 
23 
31 
32 
3321/09/2018

 

Cheers,

 

cmob

  • Anonymous , Try a new table

    ADDCOLUMNS(crossjoin(person, selectcolumns(document,"ID",[document ID],"Document",[Document])), "Date_Added new", if([ID] = [document ID], [Date_Added], blank()))

     

2 Replies

  • Anonymous , Try a new table

    ADDCOLUMNS(crossjoin(person, selectcolumns(document,"ID",[document ID],"Document",[Document])), "Date_Added new", if([ID] = [document ID], [Date_Added], blank()))

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Phenomonal reply speed as always, Amit. I tweaked the syntax a bit and then created a summary table to flatten the data as it returned some duplicates. The end result is exactly what I was after. 

    For future reference the DAX used was :


    xJoin_Document =
    ADDCOLUMNS (
        CROSSJOIN (
            Child_Documents,
            SELECTCOLUMNS (
                Child_Document_Types,
                "ID1", [DocumentTypeID],
                "Document", ( Child_Document_Types[Type] )
            )
        ),
        "Date_Added new", IF ( [ID1] = [DocumentTypeID], [Date_Added], BLANK () )
    )


    I then flattened it with:

    Flat_Document =
    SUMMARIZE (
        xJoin_Document,
        xJoin_Document[ID1],
        xJoin_Document[ChildID],
        "Date Added", MAX ( xJoin_Document[Date_Added new] )
    )

    I'll combine the two to optimise the model further.

    Cheers,
     
    cmob