cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
pmcinnis Frequent Visitor
Frequent Visitor

How do I filter rows by date range in DAX?

What do I need to add to the DAX scripts below to include only rows with dates that fall in the period January 1, 2013 to December 31, 2018?
 
For the first two scripts, there is only one table. It is called 'Data'.
For the last script, there are two tables. They are called 'Data' and 'Standards'.
For all three scripts, the date data is in column 'Date' in table 'Data'
 
Thx in advance
 
res ct dist =
  CALCULATE(
    COUNTROWS('Data'),
      FILTER(
        ALLEXCEPT('Data','Data'[Parameter]),[Sample Type]="DISTRIBUTION"))
 
det ct dist =
  CALCULATE(COUNTROWS('Data'),
    FILTER(ALLEXCEPT('Data','Data'[Parameter]),[Result - Numeric]<>BLANK()),
    FILTER('Data',[Sample Type]="DISTRIBUTION"))
 
Std/2 dist =
  IF(
    NOT(
      ISBLANK(
        CALCULATE(
          SELECTEDVALUE(Standards[Standard]),
          CROSSFILTER(Data[Parameter],Standards[Parameter],BOTH)))),
            CALCULATE(COUNTROWS(Data),
            FILTER(Data,Data[Result-Numeric-in ug/L]>=DIVIDE(RELATED(Standards[Standard]),2,-999)),
            FILTER(Data,Data[Sample Type]="DISTRIBUTION")))
2 REPLIES 2
Super User III
Super User III

Re: How do I filter rows by date range in DAX?

Hi @pmcinnis ,

try this:

res ct dist =
CALCULATE (
    COUNTROWS ( 'Data' ),
    FILTER (
        ALLEXCEPT ( 'Data', 'Data'[Parameter] ),
        [Sample Type] = "DISTRIBUTION"
            && Data[Date] >= DATE ( 2018, 1, 1 )
            && Data[Date] <= DATE ( 2018, 12, 31 )
    )
)

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

 

Community Support Team
Community Support Team

Re: How do I filter rows by date range in DAX?

Hi @pmcinnis ,

 You could refer to above suggestions. If this is not what you want, please inform me more detailed information(such as your expected output and your sample data)? Then I will help you more correctly.

Please do mask sensitive data before uploading.

Thanks for your understanding and support.
Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors