Search code examples
powerbipowerbi-desktoppowerbi-datasourcepower-bi-report-serverpowerbi-custom-visuals

How to summarize column with condition on power bi?


I'm trying to create table summary table with following conditions

enter image description here

From the Original table to summary table we have to create using the following conditions

1) select distinct ids
2) select screen name base on highest count group by id and today date
3) If two screens are same value on today date with the same id then pick the first screen

Solution

  • This yields the desired result as a calculated table.

    SummaryTable = 
    ADDCOLUMNS(
        ADDCOLUMNS(
            FILTER(
                SUMMARIZE(
                    OriginalTable,
                    OriginalTable[ID],
                    OriginalTable[StartDate]
                ),
                OriginalTable[StartDate] = TODAY()
            ),
            "Count", CALCULATE( MAX( OriginalTable[Count] ) )
        ),
        "Screen",
        VAR CurrentCount = [Count]
        RETURN CALCULATE( MIN(OriginalTable[Screen]), OriginalTable[Count] = CurrentCount )
    )
    

    Output:

    result