Pergunta

I'm very new to DAX and PowerPivots. I am using PowerPivot to pull data from an SQL server. The data I'm working with is pretty large and complex but I'm considering a simplified version of it for this question.

Let's say I have 2 columns, one that contains product names and one that contains a date that product was sold. I have a row for each time 1 unit of any product is sold.

Product | Date
Orange  | 08/13/2013
Orange  | 08/13/2013
Orange  | 08/13/2013
Apple   | 08/14/2013
Apple   | 08/16/2013
Orange  | 08/17/2013
Orange  | 08/17/2013

I want to use DAX to get a running count of how much of a product has been sold to date over the entire data set. This is what I would like to end up with.

Product | Date        | Cumulative Sales
Orange  | 08/13/2013  | 1
Orange  | 08/13/2013  | 2
Orange  | 08/13/2013  | 3
Apple   | 08/14/2013  | 1
Apple   | 08/16/2013  | 2
Orange  | 08/17/2013  | 4
Orange  | 08/17/2013  | 5

Any help would be appreciated.

EDIT: One more thing, the data is not necessarily ordered by date. I could potentially order it by date but it would require modification of some other things so my preference would be not to do so if at all possible. There are a lot of other formulas in the sheet I inherited and reordering may break something else.

Foi útil?

Solução

You can make a calculated measure in PowerPivot to handle this. If you want to get the cumulative sales for all time you can do this:

    CALCULATE(     SUM( FactSales[SalesAmount] ),
    FILTER(
        ALL( DimDate) ,
        DimDate[Datekey] <= MAX( DimDate[Datekey] )
    )
)

If you want to be able to select certain time period (ex: running total for selected weeks or months) you can do this:

 CALCULATE( SUM( FactSales[SalesAmount])  ,
                 FILTER(
                    ALLSELECTED( DimDate),
                    DimDate[Datekey] <= MAX( DimDate[Datekey] )
                )
    )

Source: Javier Guillen's blog

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top