Forum Discussion

pmcinnis's avatar
pmcinnis
Helper III
6 years ago

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

  • sturlaws's avatar
    sturlaws
    Resident Rockstar

    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.

     

  • dax's avatar
    dax
    Community Support

    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.