Forum Discussion

Jayrx7's avatar
Jayrx7
Frequent Visitor
3 years ago
Solved

Countrow not working correctly with Calculate

Hello, 

 

I tried to write a query that returns the rowcount for the rolling 28 days. Below is my query, but it isn't returning the correct output:

ROLLING 28 = CALCULATE(COUNTROWS('Incidents'), (DATESINPERIOD('Incidents'[Dates to Use],MAX('Incidents'[Dates to Use]),-28,DAY)))

When I just do a countrows with a date slicer, it returns the correct output below, the max date in my table is 9/17/22. 

 

But when I use the query above, it returns the below incorrect output. It is returning the correct total, but the counts of the item types are incorrect. 

 Thank you. 

  • Hi, Jayrx7 ;

    Try it.

    ROLLING 28 = CALCULATE(COUNTROWS('Table'), DATESINPERIOD('Table'[Date],CALCULATE( MAX('Table'[Date]),ALL('Table')),-28,DAY))

    The final show:

    slicer:

    measure.


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

2 Replies

  • HoangHugo's avatar
    HoangHugo
    Icon for Solution Specialist rankSolution Specialist

    Because, in your formula,  each item will return different Max Dates. Try this one

     

    ROLLING 28 = CALCULATE(COUNTROWS('Incidents'), (DATESINPERIOD('Incidents'[Dates to Use],MAX(ALLSELECTED('Incidents'[Dates to Use])),-28,DAY)))

     

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, Jayrx7 ;

    Try it.

    ROLLING 28 = CALCULATE(COUNTROWS('Table'), DATESINPERIOD('Table'[Date],CALCULATE( MAX('Table'[Date]),ALL('Table')),-28,DAY))

    The final show:

    slicer:

    measure.


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.