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

Dax for dynamic filter by user selection in slicer

Hi all,

 

I have a measure  which is working absolutely fine given below.

 

Measure1 = CALCULATE([sales],KEEPFILTERS('Sales'[Date]>=DATE(2011,02,5)))
        

I just want to make it dynamic. In the above measure [DATE(2011,02,5)] is hard coded. This option, I want to give to user to change it by slicer. I tried using selectedvalue measure2, like below. It does not give the output as my first measure. 

 

Measure2 =
Var SelectYear =
        FORMAT(
            SELECTEDVALUE('Calendar'[Date]),
            "yyyy")
   
Var SelectMonth =
     FORMAT(
            SELECTEDVALUE('Calendar'[Date]),
            "mm")
       
Var SelectDay =
    FORMAT(
            SELECTEDVALUE('Calendar'[Date]),
            "dd")
   
Var CalcutedSales=
    CALCULATE(
        [sales],
        KEEPFILTERS(
                    Sales[Date]>= DATE(SelectYear,SelectMonth,SelectDay)
        )
    )
return
    CalcutedSales

 

1 ACCEPTED SOLUTION

Hi @Rahul_SC ,

 

As far as I know, the value in SelectYear/SelectMonth/SelectDay part in [Measure2] are in text type. Date() only support number type. And I think you can use 'Calendar'[Date] directly in your filter place.

Measure2 =
VAR SelectDate =
    SELECTEDVALUE ( 'Calendar'[Date] )
VAR CalcutedSales =
    CALCULATE ( [sales], KEEPFILTERS ( Sales[Date] >= SelectDate ) )
RETURN
    CalcutedSales

Please make sure there is no relationship between your data table and calendar table or the relationship between them is inactive.

 

Best Regards,
Rico Zhou

 

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

2 REPLIES 2
Rahul_SC
Helper III
Helper III

adding more information :

 

the slicer contains date column from calender table. where user would select any date.

Hi @Rahul_SC ,

 

As far as I know, the value in SelectYear/SelectMonth/SelectDay part in [Measure2] are in text type. Date() only support number type. And I think you can use 'Calendar'[Date] directly in your filter place.

Measure2 =
VAR SelectDate =
    SELECTEDVALUE ( 'Calendar'[Date] )
VAR CalcutedSales =
    CALCULATE ( [sales], KEEPFILTERS ( Sales[Date] >= SelectDate ) )
RETURN
    CalcutedSales

Please make sure there is no relationship between your data table and calendar table or the relationship between them is inactive.

 

Best Regards,
Rico Zhou

 

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

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.

Top Solution Authors