DAX Keepfilter

dicken

Active Member
Joined
Feb 12, 2022
Messages
283
Office Version
  1. 365
Platform
  1. Windows
Hi,
Cross posted Excel Forum ;
Excel Formula:
https://www.excelforum.com/office-365/1399068-dax-filtering-between-dates-with-keepfilter.html#post5787380https://www.excelforum.com/office-365/1399068-dax-filtering-between-dates-with-keepfilter.html#post5787380

Can someone help with this I have a Keepfilter measure;

Excel Formula:
CALCULATE([TotalUnits],KEEPFILTERS( dDateT[Date] >= DATE( 2020,3,1) && dDateT[Date] <= DATE(2020,7,31) ))

but I would like to take the dates from another table, not use DATE( ) ,

Excel Formula:
CALCULATE([TotalUnits],KEEPFILTERS( dDateT[Date] >= MAX(pdate[StardD]) && dDateT[Date] <= MAX(pdate[EndD] ) ))


and while this give the correct overall total, when dropped into a table or matrix it does not 'see' the dates there, it's as if I'd just used filter.
I have got aroung this by using the following;

Excel Formula:
Bwrwn Pdates =
CALCULATE (
    [TotalUnits],
    KEEPFILTERS (
        FILTER (
            ALL ( dDateT[Date] ),
            dDateT[Date] <= MAX ( Pdate[EndDate] )
                && dDateT[Date] >= MAX ( Pdate[Sdate] )
        )
    )
)

This works but I don't know why the other doesn't can anyone help?
Richard.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Keepfilters is clashing with ALL in this formula; they do the opposite thing.
as for why it doesn’t work, it’s impossible to say without you sharing the visual, and also explaining which columns are providing filter context, and what the model looks like.
 
Upvote 0
Keepfilters is clashing with ALL in this formula; they do the opposite thing.
as for why it doesn’t work, it’s impossible to say without you sharing the visual, and also explaining which columns are providing filter context, and what the model looks like.
When you say keepfilters is clashing with ALL, in the first example I'm not use ALL, the tables are one fact table, date and sales,
then a dates to filter between table two columns start and end, and then the calendar table,
as I said above keepfiltes works when I just use DATE() to give the dates I want but if I take them from the table using MAX, which I believe should then work as a scaler value, the correct total is returned but I get it for each row, I have attached the source excel file at excel forum,
when you say share a visual in what form?

Richard.
 
Upvote 0
Keepfilters is clashing with ALL in this formula; they do the opposite thing.
as for why it doesn’t work, it’s impossible to say without you sharing the visual, and also explaining which columns are providing filter context, and what the model looks like.
Screen shot included.
I've recreated the scenario ; The first uses, this works fine;

Excel Formula:
CALCULATE([TotalUnits],KEEPFILTERS(Ddate[Date] >= DATE(2002,2,1) && Ddate[Date] <= DATE(2002,2,10) ))


The second uses , this has two problems;

Excel Formula:
CALCULATE([TotalUnits],KEEPFILTERS(Ddate[Date]<=MAX(dimTest[ EndD ]) && Ddate[Date]>=MAX(dimTest[StartD]) )) )

Which sees the Start but not the end date, but does not see the external 'AND' operation I thought keepfilters did,

The Third uses ; this has one problem;
Excel Formula:
CALCULATE(
    [TotalUnits],KEEPFILTERS( FILTER(ALL(Ddate[Date]),Ddate[Date]<= MAX(dimTest[ EndD ]) && Ddate[Date]>= MAX(dimTest[StartD]) )) ) )

Which does see the external date, the AND part but again, does not recognize the End date, do,
So two problems, one regarding the KF and also not seeing the End date, the table for the two dates is not connected,
do I need to use USERELATIONSHIP and link both start and end dates fact table?

Richard


1675612420866.png
 
Upvote 0
Hi,

1675776638000.png

This was how I originally had it, but as I was only using the date as a values I then disconnected it, but what I did was after watch
something on sqlbi, decided to use the values in a variable in it seem to work, so as seen below
this works
Excel Formula:
KFvar = 
VAR mind = MAX(Table2[StartD]) 
VAR maaxd = MAX(Table2[EndD ]) 
RETURN 
CALCULATE([TotalUnits],KEEPFILTERS(dDate[Date] <= maaxd && dDate[Date] >= mind ) )

but does not, or at least does the see the external filter context,
Excel Formula:
Direct = IF([TotalUnits],  
                                CALCULATE([TotalUnits],KEEPFILTERS(dDate[Date] >= MAX(Table2[StartD])
                                                      && dDate[Date] <= MAX(Table2[EndD ]) )))

But using filter and then wrapping in KF and it's all works again?
Excel Formula:
KFF :=
CALCULATE (
    [TotalUnits],
    KEEPFILTERS (
        FILTER (
            ALL ( dDate[Date] ),
            dDate[Date] <= MAX ( Table2[EndD ] )
                && dDate[Date] >= MAX ( Table2[StartD] )
        )
    )
)

Richard.




1675776150433.png
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,133
Members
449,098
Latest member
Doanvanhieu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top