Forum Discussion

deb_power123's avatar
deb_power123
Helper V
5 years ago
Solved

How to exclude rows selecting date slicer max and min date ranges

Hi All,

 

As per the below scenario,I need to exclude all the rows in the table Sales with columns Client,sales,salesdate and region which fall outside the selected maximum and minimum date range of the date slider.

Could anyone please suggest a DAX , I will share my DAX query which is not working.I tried to search official guides in PowerBI for selectedValues() to handle this date filter condition but nothing seems to be working.

 

I created a Calendar table with distinct values of the dates as present in the Sales Dates column of the Sales table. There is no relationship between these two tables.

 

I used the below DAX measures to handle the filtering criteria for excluding the rows:-

Below measures are meant to find maximum and minimum dates in the selection slider

MaxDate=MAX(DateDimention[Dates])

MinDate=MIN(DateDimention[Dates])

Below  ExcludedMeasure is meant to set 1 flag to the values other than  selected values which are selected for both min and max dates. I dragged and dropped it in the visual filter of my table Sales and set it to dont show.But it seems to be not working.

Please suggest how can I fix it.

ExcludeMeasure = IF (SELECTEDVALUE(Calendar,Calendar[MinDate],0,1),

                              IF (SELECTEDVALUE(Calendar,Calendar[MaxDate],0,1)

 

 

My Present Visualization and indepedent Calendar table to be used in the filter slider:-

 

Input data source [Excel]

 

ClientSalesSalesDatesRegion
A10001.1.2000USA
A1001.2.2000USA
A2004.3.2000USA
B1104.3.2000Europe
B10005.4.2000Europe
B2006.8.2001Europe
C11007.9.2001Asia
C20008.12.2001Asia
D1001.2.2002Australia
D13006.3.2002Australia
E1007.5.2002Africa

 

Expected Results :

 

If I select Minium slider date as 01.04.2001 and maximum slider date as 1.09.2001 in my[Dates] filter visualization, then it should return the below results after exluding '5.4.2001' and '6.8.2001':-

 

ClientSalesSalesDatesRegion
A10001.1.2000USA
A1001.2.2000USA
A2004.3.2000USA
B1104.3.2000Europe
C11007.9.2001Asia
C20008.12.2001Asia
D1001.2.2002Australia
D13006.3.2002Australia
E1007.5.2002Africa

 

Kind regards

Sameer

  • Hi, deb_power123 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.(All dates are in 'mm/dd/yyyy' format)

    Table:

     

    DateDimention(a calculated table):

    DateDimention = CALENDARAUTO()

     

    There is no relationship between two tables. You may create a measure as below.

    Visual Control = 
    IF(
        SELECTEDVALUE('Table'[SalesDates])<MIN(DateDimention[Date])||
        SELECTEDVALUE('Table'[SalesDates])>MAX(DateDimention[Date]),
        1,0
    )

     

    Finally you need to put the measure in the visual level filter and use 'Date' column from 'DateDimention' table to filter the result.

     

    Best Regards

    Allan

     

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

4 Replies

    • deb_power123's avatar
      deb_power123
      Helper V

      Hi ,

      Thankyou for the response.I tried  but i am getting the below error message while trying to create the measure.

       

      Could you please share the .pbix file or let me know where i am making mistake?

  • v-alq-msft's avatar
    v-alq-msft
    Icon for Community Support rankCommunity Support

    Hi, deb_power123 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.(All dates are in 'mm/dd/yyyy' format)

    Table:

     

    DateDimention(a calculated table):

    DateDimention = CALENDARAUTO()

     

    There is no relationship between two tables. You may create a measure as below.

    Visual Control = 
    IF(
        SELECTEDVALUE('Table'[SalesDates])<MIN(DateDimention[Date])||
        SELECTEDVALUE('Table'[SalesDates])>MAX(DateDimention[Date]),
        1,0
    )

     

    Finally you need to put the measure in the visual level filter and use 'Date' column from 'DateDimention' table to filter the result.

     

    Best Regards

    Allan

     

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