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
Mihu
New Member

distinct count for previous x periods withoud date table

Hi everyone,

 

I am facing challenge that i need to aggregate data for last few periods but these periods are not date table and there is no any dependence where period start and end so using parallelperiod etc formulas is not possible;D

 

So here is my sample data:

employee idperiod
1201801
2201801
3201801
4201801
1201802
3201802
4201802
1201803
3201803
4201803
5201803
1201804
3201804
4201804
5201804
6201804

And I need to show it this way in PBI:

periodemployees distinctemployees distinct 3 periods
20180144
20180234
20180345
20180455

So employees distinct is a distinct count of employees in a period by their id,

employees distinct 3 periods is a distinct count of employees from last 3 periods.

 

I tried to combine calculate, filter and lookupvalue to filter data for last three  periods like this:

CALCULATE(DISTINCTCOUNT('Employee by Period'[Employee ID]),FILTER( Period, LOOKUPVALUE(Period[Name],Period[Name],FORMAT(VALUE(Period[Name]) - 2,"######")) || LOOKUPVALUE(Period[Name],Period[Name],FORMAT(VALUE(Period[Name]) - 1,"######")) || VALUE(Period[Name]) ))

But it is still showing data only for 'current period' like 'employees distinct' described above.

 

If you have any idea how to deal with it i would really appriciate it 🙂

1 ACCEPTED SOLUTION

@Mihu ,

 

You can create two measures using dax below:

employees distinct = COUNT('Table'[employee id])

employees distinct 3 periods = 
VAR Current_Period = MAX('Table'[period])
RETURN
CALCULATE(DISTINCTCOUNT('Table'[employee id]), FILTER(ALL('Table'), 'Table'[period] <= Current_Period && 'Table'[period] >= Current_Period - 2 ))

Capture.PNG 

 

Community Support Team _ Jimmy Tao

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

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

@Mihu ,

 

Isn't the expected table like below? In addtion, I'm still not very clear about "last three  periods" you mentioned, could you please share more details?

period employees distinct employees distinct 3 periods
201801 4 4
201802 3 4
201803 4 5
201804 5 5

 

Regards,

Jimmy Tao

@v-yuta-msft thank you for answer, yea the result table is expected as you posted, i edited it.

 

According to your question in example of 201803 period.

For 201803 period we have employees 1,3,4,5

for 201802 period we have employees 1,3,4

and for 201801 period we have employees 1,2,3,4

So unique employees for last 3 periods of 201803 is 1,2,3,4,5 and the sum is 5.

 

BR,

Mihu

 

 

@Mihu ,

 

You can create two measures using dax below:

employees distinct = COUNT('Table'[employee id])

employees distinct 3 periods = 
VAR Current_Period = MAX('Table'[period])
RETURN
CALCULATE(DISTINCTCOUNT('Table'[employee id]), FILTER(ALL('Table'), 'Table'[period] <= Current_Period && 'Table'[period] >= Current_Period - 2 ))

Capture.PNG 

 

Community Support Team _ Jimmy Tao

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.