Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
pmcinnis
Helper III
Helper III

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
dax
Community Support
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.

 

sturlaws
Resident Rockstar
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.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.