Forum Discussion

davegw's avatar
davegw
Frequent Visitor
6 years ago
Solved

Cumulative/Running Total visual when some rows have no data

I need to create a runningtotal for sales based on the number of days before an event. My fact table includes a join to a key called DaysBeforeEventKey. The reason for using this rather than date is ...
  • davegw's avatar
    davegw
    6 years ago

    I've now found a solution (I'm not sure it is the perfect soultion and may now contains some redundancy but at least it works).

     

    Here's my new version of the measure:-

    PCR Ticket Volume Running Total 2019 =
    VAR LastDay =
        MAXX (
            FILTER (
                ( 'Fact Sales' ),
                RELATED ( 'Dimension Event'[Event Name] ) = "xxxx 2019"
            ),
            'Fact Sales'[DaysBeforeEventKey]
        )
    VAR FirstDay =
        MINX (
            FILTER (
                ( 'Fact Sales' ),
                RELATED ( 'Dimension Event'[Event Name] ) = "xxxx 2019"
            ),
            'Fact Sales'[DaysBeforeEventKey]
        )
    RETURN
        IF (
            SELECTEDVALUE ( 'Fact Sales'[DaysBeforeEventKey] ) > LastDay,
            BLANK (),
            IF (
                SELECTEDVALUE ( 'Fact Sales'[DaysBeforeEventKey] ) < FirstDay,
                BLANK (),
                CALCULATE (
                    SUM ( 'Fact Sales'[Ticket Quantity] ),
                    'Dimension Event'[Event Name] = "xxxx 2019",
                    'Dimension Event'[EventYear] = 2019,
                    FILTER (
                        ALLSELECTED ( 'Fact Sales' ),
                        AND (
                            'Fact Sales'[DaysBeforeEventKey]
                                <= SELECTEDVALUE ( 'Fact Sales'[DaysBeforeEventKey] ),
                            NOT ( ISBLANK ( SELECTEDVALUE ( 'Fact Sales'[DaysBeforeEventKey] ) ) )
                        )
                    )
                )
            )
        )

     

    And how my visual now looks

     

    Final Visual (As required)