cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
anubb688
New Member

CALCULATE, FILTER and ALL

Hi, below DAX does not display correct result. What this code should be doing is displaying "RPMD" for previous 10 periods. Each period is a week. I suspect the problem lands possibly caused by misusing of CALCULATE, FILTER and ALL. Please advise.

 

RPMD = DIVIDE([Revenue Calculated], [Est Exp], 0)

 

RPMD Last 10 =
VAR _selecteddate =
    MIN ( 'Calendar'[Date] )
RETURN
    CALCULATE (
        [RPMD],
        FILTER (
            ALL ( 'Calendar'[Date] ),
            IF (
                'Calendar'[Date] = _selecteddate - 7,
                'Calendar'[Date],
                IF (
                    'Calendar'[Date] = _selecteddate - 14,
                    'Calendar'[Date],
                    IF (
                        'Calendar'[Date] = _selecteddate - 21,
                        'Calendar'[Date],
                        IF (
                            'Calendar'[Date] = _selecteddate - 28,
                            'Calendar'[Date],
                            IF (
                                'Calendar'[Date] = _selecteddate - 35,
                                'Calendar'[Date],
                                IF (
                                    'Calendar'[Date] = _selecteddate - 42,
                                    'Calendar'[Date],
                                    IF (
                                        'Calendar'[Date] = _selecteddate - 49,
                                        'Calendar'[Date],
                                        IF (
                                            'Calendar'[Date] = _selecteddate - 56,
                                            'Calendar'[Date],
                                            IF (
                                                'Calendar'[Date] = _selecteddate - 63,
                                                'Calendar'[Date],
                                                IF ( 'Calendar'[Date] = _selecteddate, 'Calendar'[Date], BLANK () )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

1 ACCEPTED SOLUTION
Greg_Deckler
Super User IV
Super User IV

@anubb688 Probably, Why not just get the current date and if you want the past 10 periods (each a week) then something like:

RPMD Last 10 = 
  VAR __SelectedDate = MIN('Calendar'[Date])
  VAR __10Prior = __SelectedDate - 70
RETURN
  CALCULATE([RPMD],FILTER('Calendar','Calendar'[Date]>=__10Prior && 'Calendar'[Date]<=__SelectedDate))

---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
Greg_Deckler
Super User IV
Super User IV

@anubb688 Probably, Why not just get the current date and if you want the past 10 periods (each a week) then something like:

RPMD Last 10 = 
  VAR __SelectedDate = MIN('Calendar'[Date])
  VAR __10Prior = __SelectedDate - 70
RETURN
  CALCULATE([RPMD],FILTER('Calendar','Calendar'[Date]>=__10Prior && 'Calendar'[Date]<=__SelectedDate))

---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

anubb688_0-1627586735890.png

It somehow shows a dot instead of line chart which i have selected

Maybe:

RPMD Last 10 = 
  VAR __SelectedDate = MIN('Calendar'[Date])
  VAR __10Prior = __SelectedDate - 70
RETURN
  CALCULATE([RPMD],FILTER(ALL('Calendar'),'Calendar'[Date]>=__10Prior && 'Calendar'[Date]<=__SelectedDate))

It's really hard to know with such incomplete information.


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Your code worked when I tweaked my beneath formulas. Thanks. I'll mark yours as solution since I found my direction.

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.