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
Anonymous
Not applicable

Advance Date Filter in DAX

Hi All I have an issue I'm trying to solve. 

I have a set of gym members who have personal trainers. The members have dates that they activated and deactivated their memberships. I want to be able to calculate the number of active members a trainer had in a particular week.

For example, the previous week ran from 28 Oct - 03 November (Mon-Sun) and to get what I need I'd use the advance visual level filter and set the Date Active to "on or before" 03 Nov and "Is Blank". I'd add another advance visual level filter and set the Date In Active to "on or after" 28 Oct or "is blank". 

Using this method gives what I want but I need this to be done automatically because I'd have to manually update the filters at the beginning of a new week which is not efficient. Any thoughts on how I can achieve the same results using DAX?

 

Here's the link to a demo pbix file: https://drive.google.com/open?id=18G7TNnrD1zNbQWfrhotYYoCxWoqaKI6Q

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

Hi @Anonymous ,

 

Please check following steps as below:

1. Create calculated column:

     isactive_lastweek =

     IF (

         ISBLANK ( 'Table'[DateInactivated] ),

         "Yes",

         IF (

             WEEKNUM ( 'Table'[DateInactivated], 2 ) + 1

                 >= WEEKNUM ( NOW (), 2 ),

             "Yes",

             "No"

         )

     )

2. Add filter to visual:

1.PNG

3. Result would be shown as below:

2.PNG

Pbix as attached, hopefully works for you.

 

Best Regards,

Jay

 

Community Support Team _ Jay Wang

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

3 REPLIES 3
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please check following steps as below:

1. Create calculated column:

     isactive_lastweek =

     IF (

         ISBLANK ( 'Table'[DateInactivated] ),

         "Yes",

         IF (

             WEEKNUM ( 'Table'[DateInactivated], 2 ) + 1

                 >= WEEKNUM ( NOW (), 2 ),

             "Yes",

             "No"

         )

     )

2. Add filter to visual:

1.PNG

3. Result would be shown as below:

2.PNG

Pbix as attached, hopefully works for you.

 

Best Regards,

Jay

 

Community Support Team _ Jay Wang

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Anonymous
Not applicable

@v-jayw-msft I have one issue with this solution that I just stumbled upon, week number does not take into account the year the week number is in. If I say week number must be grater than or equal to current week number, then data from the last years week number will get filtered out. Is there a way around this?

Anonymous
Not applicable

@v-jayw-msft thank you so much for this solution, it works perfectly. The brilliance of this is that it actually asks the right question, "Was the member active last week?", which is something I overlooked. 

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.