Forum Discussion
Calculate a total between two dates
- Anonymous1 year ago
Hi, maurcoll
You can try the following dax to achieve your need.Before = VAR _minDate = CALCULATE(MIN('Table'[Offer Start Date]),ALLEXCEPT('Table','Table'[Customer])) VAR _counts = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Order Date]<_minDate)) RETURN _counts Between = VAR _minDate = CALCULATE(MIN('Table'[Offer Start Date]),ALLEXCEPT('Table','Table'[Customer])) VAR _maxDate = CALCULATE(MAX('Table'[Offer End Date]),ALLEXCEPT('Table','Table'[Customer])) VAR _counts = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Order Date]>=_minDate && 'Table'[Order Date]<=_maxDate)) RETURN _counts After = VAR _minDate = CALCULATE(MIN('Table'[Offer Start Date]),ALLEXCEPT('Table','Table'[Customer])) VAR _maxDate = CALCULATE(MAX('Table'[Offer End Date]),ALLEXCEPT('Table','Table'[Customer])) VAR _today = TODAY() VAR _counts = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Order Date]>_maxDate && 'Table'[Order Date]<=_today)) RETURN _countsBest Regards,
Yang
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Hi, maurcoll
You can try the following dax to achieve your need.
Before =
VAR _minDate = CALCULATE(MIN('Table'[Offer Start Date]),ALLEXCEPT('Table','Table'[Customer]))
VAR _counts = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Order Date]<_minDate))
RETURN
_counts
Between =
VAR _minDate = CALCULATE(MIN('Table'[Offer Start Date]),ALLEXCEPT('Table','Table'[Customer]))
VAR _maxDate = CALCULATE(MAX('Table'[Offer End Date]),ALLEXCEPT('Table','Table'[Customer]))
VAR _counts = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Order Date]>=_minDate && 'Table'[Order Date]<=_maxDate))
RETURN
_counts
After =
VAR _minDate = CALCULATE(MIN('Table'[Offer Start Date]),ALLEXCEPT('Table','Table'[Customer]))
VAR _maxDate = CALCULATE(MAX('Table'[Offer End Date]),ALLEXCEPT('Table','Table'[Customer]))
VAR _today = TODAY()
VAR _counts = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Order Date]>_maxDate && 'Table'[Order Date]<=_today))
RETURN
_counts
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum