Aggregated sum in DAX

2019-06-13 03:20发布

问题:

I'm leasing a car, which I use my self, but also rent out for other people to use. I have 2000km I can drive each month, so I'm trying to do an area pivot graph which will track how much I use it vs how much it's rented out.

I have a table column consisting of the rented mileage and my own mileage

 ___________________________________
|Date    |Rented mileage|Own mileage|
|23/03-18|           315|        117|
|07-04-18|           255|        888|
|07/04-18|           349|          0|
|13/04-18|           114|          0|
|21/04-18|           246|        113|
|28/04-18|          1253|          0|
|01/05-18|          1253|          0|

So far I have two measures:

RentedMileage:=SUM(Table1[Rented Mileage])
OwnMileage:=SUM(Table1[Own Mileage])

Which, when I plot to the pivot chart looks like this:

I would like the mileage to be aggregated and have a Line which shown when I'm exceeding my 2000 km limit, so it would look something like this:

But I can't for the life of me figure out how to do an aggregated value of my table?

回答1:

The issue was solved by adding following line of code to the measure:

Cumulative Quantity :=
    CALCULATE (
        SUM ( Transactions[Quantity] ),
        FILTER (
            ALL ( 'Date'[Date] ),
            'Date'[Date] <= MAX ( 'Date'[Date] )
        )
    )