none
How to calculate subtotal correctly when using sameperiodlastyear RRS feed

  • Question

  • Hi everyone, I am trying to calculate number of orders in a certain periods and compare it with the same period of last year. 

     

    Problem is that I do get correct numbers for each rows, but I get wrong for subtotal. Could anyone help me to figure out how to calculate correctly for subtotals?

     

    Applied DAX are,

    ordercount = DISTINCTCOUNT(orders[ordernumbers])

    PYordercount = CALCULATE(DISTINCTCOUNT(orders[ordernumbers]), SAMEPERIODLASTYEAR(shipment[shippingdate]))

     

    Orderdate ordercount PYordercount
    2019/7/4 37 39
    2019/7/5 53 50
    2019/7/6 52 24
    2019/7/7 34 34
    2019/7/8 19 33
    2019/7/9 32 28
    2019/7/10 56 37
    2019/7/11 40 38
    subtotal 323 993

     

    Thanks in advance,

    Hisashi


    Saturday, July 13, 2019 1:19 AM

Answers

  • Hi Hisashi,

    Try this measure:

    PYordercount =
    SUMX (
        VALUES ( orders[Orderdate] ),
        CALCULATE (
            DISTINCTCOUNT ( orders[ordernumbers] ),
            SAMEPERIODLASTYEAR ( shipment[shippingdate] )
        )
    )
    • Marked as answer by yamayahisashi Monday, July 15, 2019 5:13 AM
    Saturday, July 13, 2019 9:42 PM

All replies