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
jsteffe
Helper III
Helper III

Problem with a date filter

Hello,

I produced this page in Power BI :

 

connexion.png

When I change the dates : my table refreshs correctly.
But if I change the formula of my measure "Statut" and I replace BLANK() by "inactive", the filter does not seem to work anymore.

Old measure : statut = if(ISBLANK([daysElapsed]),BLANK(),if([daysElapsed]<=10,"active","passive"))

New measure : statut = if(ISBLANK([daysElapsed]),"inactive",if([daysElapsed]<=10,"active","passive"))
Just replacing BLANK() by "inactive", I get this result :

connexion2.png

 

The filter on my table shows that the date should be before 25/01/2022 but I get in my results some lines after 25/01/2022 ... (the ones for which status = "inactive").

 

Why do I get these lines ?

 

Thanks for your help ...

 

 





 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @jsteffe ,

Slicer just filters the data of the columns in the connexions table, but the measure will not be changed by the selection of the slicer

You can use Flag to filter the date, only the date selected by the slicer is displayed in Visual

Here are the steps you can follow:

1. Create measure.

Flag =
var _min=MIN('Calendar'[Date])
var _max=MAX('Calendar'[Date])
return
IF(
    MAX('connexions'[lastConnexionDate])>=_min&&MAX('connexions'[lastConnexionDate])<=_max,1,0)

2. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1645078648746.png

3. Result:

vyangliumsft_1-1645078648753.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

6 REPLIES 6
v-yangliu-msft
Community Support
Community Support

Hi  @jsteffe ,

Slicer just filters the data of the columns in the connexions table, but the measure will not be changed by the selection of the slicer

You can use Flag to filter the date, only the date selected by the slicer is displayed in Visual

Here are the steps you can follow:

1. Create measure.

Flag =
var _min=MIN('Calendar'[Date])
var _max=MAX('Calendar'[Date])
return
IF(
    MAX('connexions'[lastConnexionDate])>=_min&&MAX('connexions'[lastConnexionDate])<=_max,1,0)

2. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1645078648746.png

3. Result:

vyangliumsft_1-1645078648753.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

bcdobbs
Super User
Super User

Is the date column in your table the same as the date column in your slicer?

Could you share a picture of your model or a demo pbix file?



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

I get 2 dates :
- one in my table connexions (the one which is in the table)

- one in my calendar date (which is in my slicer).

I put a relationship betxeen these 2 dates in my model.

You get the pbix file there :
https://filez.agro-bordeaux.fr/xs57gp

 

Thanks,

Ok, that's really made me think. Hoping @Greg_Deckler@marcorusso  or @AlbertoFerrari  can confirm my conclusion.

 

I reduced it down as far I could to remove any issues I could think of and looked at the result query from the table in DAX studio. That included creating a very basic date table (NewDate) and replacing your status measure so it simply returns 1 regardless. Tidied up query in DAX Studio as follows:

 

 

DEFINE
  VAR DateFilterTable = 
    FILTER(
      VALUES('NewDate'[Date]),
      'NewDate'[Date] < DATE(2022, 1, 26)
    )

  VAR ResultTable = 
    SUMMARIZECOLUMNS(
      'connexions'[lastConnexionDate],
      DateFilterTable,
      "status", 1
    )


EVALUATE
  ResultTable

ORDER BY
  'connexions'[lastConnexionDate] DESC

 


Even in this simplified state you still get the same issue:

bcdobbs_0-1644529560178.png

 

Going back to the definition of SUMMARIZECOLUMNS which is what PowerBi uses in the background for that visual there's the following statement:

 

"Filters in SUMMARIZECOLUMNS only apply to group-by columns from the same table and to measures. They do not apply to group-by columns from other tables directly, but indirectly through the implied non-empty filter from measures. In order to apply a filter to the group-by column unconditionally, apply the filter through a CALCULATETABLE function that evaluates SUMMARIZECOLUMNS."

In short because you're grouping by the date column in your fact table the filter from the date table has no effect. In fact it never did however it looked like it was because your original measure was returning blank. (Note the line "indirectly through the implied non-empty filter from measures").

 

In order to fix it you need to use the date column from your date table in the visual and then I suspect may have to tweak your original measure to turn it around.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Hello,

First, thanks a lot for your answer.
I don't understand clearly your sentence : "In fact it never did however it looked like it was because your original measure was returning blank." . The result seems to be good when my measure returns blank.

Second, I changed my table using the calendar date column rather than my connexiondate.
I had to change the measure "DaysElapsed" as follow :
daysElapsed=

var dmin=min('Calendar'[Date])
var dmax= CALCULATE(MAX('Calendar'[Date]),ALLSELECTED('Calendar'[Date]))
return DATEDIFF(dmin, dmax, DAY)
 
This solution seems to works ...
So thanks a lot for your help. I just want to understand at last why I get the same results with my first measure which was :
statut = if(ISBLANK([daysElapsed]),BLANK(),if([daysElapsed]<=10,"active","passive"))

The measure daysElapsed was daysElapsed= DATEDIFF(min(connexions[lastConnexionDate]), MAX('Calendar'[Date]) , DAY)

 

You are correct, nice diagnosis.

SUMMARIZECOLUMNS is likely to be the king of DAX shenanigans, the one you depicted is one of the nicest.

Alberto Ferrari - SQLBI

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.