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

Count users from previous dates, based on slicer selections

Hi experts, 

 

I'm new to dax and I want to count the number of users registered from the previous period selected on a slicer. DimTimeRegister[Date]) is referred to the slicer and DimTimeRegister[Date_Name] is from my master calendar

In this example, if I have selected this dates, the idea is to count the # of users of previous 6 days (30/06/2019 - 24/06/2019)

 

periodo.png

 

This is the model, where the slicer is DimTimeRegister[Date]:

Model.png

 

I added an advance card, but it's not working.

And this is my dax formula

 

 
registered users. prev. selected = 
  calculate( 
        distinctcount(DimFan[IdUser]); 
        FILTER(all(DimTimeRegister); DimTimeRegister[Date_Name] >= max(DimTimeRegister[Date])+DATEDIFF(min(DimTimeRegister[Date]); max(DimTimeRegister[Date]);DAY)); 
        FILTER(all(DimTimeRegister); DimTimeRegister[Date_Name] <= min(DimTimeRegister[Date]))
    )
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

I could solve the problem. If someone is in the same situation, here's what I did:

I've created two dates measures, to get the max and min date of the slicer:

DATE_INI = min(DimTime[Date])
DATE_MAX = max(DimTime[Date])

Then, I did create my measure
Users period before = 
  var rang = DATEDIFF([DATE_INI];[DATE_MAX];DAY)+1
  return
  CALCULATE(
      distinctcount([IdUser]);
      DATESINPERIOD(DimTime[Date];[DATE_INI];-rang;DAY)      
  )
DimTime[Date] is the slicer. It works for me perfect

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

I could solve the problem. If someone is in the same situation, here's what I did:

I've created two dates measures, to get the max and min date of the slicer:

DATE_INI = min(DimTime[Date])
DATE_MAX = max(DimTime[Date])

Then, I did create my measure
Users period before = 
  var rang = DATEDIFF([DATE_INI];[DATE_MAX];DAY)+1
  return
  CALCULATE(
      distinctcount([IdUser]);
      DATESINPERIOD(DimTime[Date];[DATE_INI];-rang;DAY)      
  )
DimTime[Date] is the slicer. It works for me perfect
v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

 

I suggest you try using a irrelative date as a date slicer.  I create a sample you can reference to modify yours.

 

I created a calendar table and use the date as a slicer to filter. And there is no relationship among the tables.

Measure = CALCULATE(DISTINCTCOUNT(DimFan[IdUser]),FILTER(DimTimeRegister,DimTimeRegister[Date_Name] >= MIN('Table'[Date]) && DimTimeRegister[Date_Name] <= MAX('Table'[Date])))

1.png2.png

If it still don’t work, please share more details and post some sample data. Then we can help you as soon as possible.

 

Best Regards,

Xue Ding 

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

Best Regards,
Xue Ding
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.