Forum Discussion

KevinGesquiere's avatar
KevinGesquiere
Frequent Visitor
8 years ago
Solved

Table with measures over different periods

Is it possible to show a table with measures over different periods? It probably does, but how should I get started? To be more precise, the data is coming from an orders table where we want an over...
  • v-jiascu-msft's avatar
    v-jiascu-msft
    8 years ago

    Hi KevinGesquiere,

     

    Please check out the demo in the attachment.

    1. These conditions aren't in the source table, we can create one.

    Col                                            ID

    % open orders 1
    % closed orders < 5days 2
    % closed orders 5 - 15 days 3
    % closed orders > 15days 4

    2. We also need a date table.

     

    Calendar = CALENDARAUTO()

    3. Don't establish relationships.

    4. Add calculated column to calculate days.

    DaysUsed = DATEDIFF([Orderdate], [DateOrderClosed],DAY)

    5. Create three measures.

    Last Months =
    VAR typeID =
        MAX ( Table2[ID] )
    RETURN
        IF (
            typeID = 1,
            CALCULATE (
                COUNT ( Table1[Id] ),
                FILTER (
                    'Table1',
                    ISBLANK ( Table1[DateOrderClosed] ) = TRUE ()
                        && Table1[Orderdate] >= EOMONTH ( TODAY (), -1 )
                )
            ),
            IF (
                typeID = 2,
                CALCULATE (
                    COUNT ( Table1[Id] ),
                    FILTER (
                        'Table1',
                        ISBLANK ( Table1[DateOrderClosed] ) = FALSE ()
                            && Table1[Orderdate] >= EOMONTH ( TODAY (), -1 )
                            && Table1[DateOrderClosed] <= TODAY ()
                            && 'Table1'[DaysUsed] < 5
                    )
                ),
                IF (
                    typeID = 3,
                    CALCULATE (
                        COUNT ( Table1[Id] ),
                        FILTER (
                            'Table1',
                            ISBLANK ( Table1[DateOrderClosed] ) = FALSE ()
                                && Table1[Orderdate] >= EOMONTH ( TODAY (), -1 )
                                && Table1[DateOrderClosed] <= TODAY ()
                                && 'Table1'[DaysUsed] <= 15
                                && 'Table1'[DaysUsed] >= 5
                        )
                    ),
                    IF (
                        typeid = 4,
                        CALCULATE (
                            COUNT ( Table1[Id] ),
                            FILTER (
                                'Table1',
                                ISBLANK ( Table1[DateOrderClosed] ) = FALSE ()
                                    && Table1[Orderdate] >= EOMONTH ( TODAY (), -1 )
                                    && Table1[DateOrderClosed] <= TODAY ()
                                    && 'Table1'[DaysUsed] > 15
                            )
                        ),
                        0
                    )
                )
            )
        )
    

     

     

    Last 6 Months =
    VAR typeID =
        MAX ( Table2[ID] )
    RETURN
        IF (
            typeID = 1,
            CALCULATE (
                COUNT ( Table1[Id] ),
                FILTER (
                    'Table1',
                    ISBLANK ( Table1[DateOrderClosed] ) = TRUE ()
                        && Table1[Orderdate] >= EOMONTH ( TODAY (), -6 )
                )
            ),
            IF (
                typeID = 2,
                CALCULATE (
                    COUNT ( Table1[Id] ),
                    FILTER (
                        'Table1',
                        ISBLANK ( Table1[DateOrderClosed] ) = FALSE ()
                            && Table1[Orderdate] >= EOMONTH ( TODAY (), -6 )
                            && Table1[DateOrderClosed] <= TODAY ()
                            && 'Table1'[DaysUsed] < 5
                    )
                ),
                IF (
                    typeID = 3,
                    CALCULATE (
                        COUNT ( Table1[Id] ),
                        FILTER (
                            'Table1',
                            ISBLANK ( Table1[DateOrderClosed] ) = FALSE ()
                                && Table1[Orderdate] >= EOMONTH ( TODAY (), -6 )
                                && Table1[DateOrderClosed] <= TODAY ()
                                && 'Table1'[DaysUsed] <= 15
                                && 'Table1'[DaysUsed] >= 5
                        )
                    ),
                    IF (
                        typeid = 4,
                        CALCULATE (
                            COUNT ( Table1[Id] ),
                            FILTER (
                                'Table1',
                                ISBLANK ( Table1[DateOrderClosed] ) = FALSE ()
                                    && Table1[Orderdate] >= EOMONTH ( TODAY (), -6 )
                                    && Table1[DateOrderClosed] <= TODAY ()
                                    && 'Table1'[DaysUsed] > 15
                            )
                        ),
                        0
                    )
                )
            )
        )
    
    Last 2 Months =
    VAR typeID =
        MAX ( Table2[ID] )
    RETURN
        IF (
            typeID = 1,
            CALCULATE (
                COUNT ( Table1[Id] ),
                FILTER (
                    'Table1',
                    ISBLANK ( Table1[DateOrderClosed] ) = TRUE ()
                        && Table1[Orderdate] >= EOMONTH ( TODAY (), -2 )
                )
            ),
            IF (
                typeID = 2,
                CALCULATE (
                    COUNT ( Table1[Id] ),
                    FILTER (
                        'Table1',
                        ISBLANK ( Table1[DateOrderClosed] ) = FALSE ()
                            && Table1[Orderdate] >= EOMONTH ( TODAY (), -2 )
                            && Table1[DateOrderClosed] <= TODAY ()
                            && 'Table1'[DaysUsed] < 5
                    )
                ),
                IF (
                    typeID = 3,
                    CALCULATE (
                        COUNT ( Table1[Id] ),
                        FILTER (
                            'Table1',
                            ISBLANK ( Table1[DateOrderClosed] ) = FALSE ()
                                && Table1[Orderdate] >= EOMONTH ( TODAY (), -2 )
                                && Table1[DateOrderClosed] <= TODAY ()
                                && 'Table1'[DaysUsed] <= 15
                                && 'Table1'[DaysUsed] >= 5
                        )
                    ),
                    IF (
                        typeid = 4,
                        CALCULATE (
                            COUNT ( Table1[Id] ),
                            FILTER (
                                'Table1',
                                ISBLANK ( Table1[DateOrderClosed] ) = FALSE ()
                                    && Table1[Orderdate] >= EOMONTH ( TODAY (), -2 )
                                    && Table1[DateOrderClosed] <= TODAY ()
                                    && 'Table1'[DaysUsed] > 15
                            )
                        ),
                        0
                    )
                )
            )
        )
    

    Best Regards,

    Dale