cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Nickpw
Frequent Visitor

DAX ALL not working as expected using date

Hi,

 

I have a measure that aggregate sales for the last seven days, see below. I want this to ignore the date slicer. However that isn't happening. The value should be £220.77K for the last seven days.  But if I change the date slicer the value changes and is instead showing the last seven day value from the 06.09.2021.

 

Can anyone help me understand why this is happening?

 

Measure = CALCULATE (
    'Measures Table'[Sum_Gross_Sales],
    DATESBETWEEN (
        'Calendar'[Date],
        MAX ( 'Calendar'[Date] ) - 7,
        MAX ( 'Calendar'[Date] ) - 1
    ), ALL('Calendar'[Date])
)

 

Screenshot 2022-08-09 115125.png

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

The ALL('Calendar'[Date]) is not being applied to the DATESBETWEEN function, it is only being applied to the [Sum_gross_sales] measure, so when you call MAX('Calendar'[Date]) the slicer is still in effect. 

If your Calendar table is marked as a date table then you don't need to remove filters from the 'Calendar'[Date] column if you apply another filter to that column, DAX takes care of that automatically. Try using

Last 7 days = CALCULATE( [Sum_Gross_Sales], DATESBETWEEN( 'Calendar'[Date], TODAY() -7, TODAY() - 1) )

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

Could you please try the below measure if it shows the outcome that is expected?

 

Measure: =
VAR _lastdateincalendartable =
    CALCULATE ( MAX ( 'Calendar'[Date] ), REMOVEFILTERS () )
RETURN
    CALCULATE (
        'Measures Table'[Sum_Gross_Sales],
        DATESBETWEEN (
            'Calendar'[Date],
            _lastdateincalendartable - 7,
            _lastdateincalendartable - 1
        )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


johnt75
Super User
Super User

The ALL('Calendar'[Date]) is not being applied to the DATESBETWEEN function, it is only being applied to the [Sum_gross_sales] measure, so when you call MAX('Calendar'[Date]) the slicer is still in effect. 

If your Calendar table is marked as a date table then you don't need to remove filters from the 'Calendar'[Date] column if you apply another filter to that column, DAX takes care of that automatically. Try using

Last 7 days = CALCULATE( [Sum_Gross_Sales], DATESBETWEEN( 'Calendar'[Date], TODAY() -7, TODAY() - 1) )

Thank you John, that solved my issues.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors