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
_Melenios_
Helper I
Helper I

Dim Calendar Table Relationship with other Table

Dear all,

 

I have a Calendar table which i use as a reference for my  dates-months slicers and i would like to create a relationship with an employee table to track down any changes/ upcoming moves that occured from one department to another in any given month.

 

The problem here is since not all the employees are changing departments every month if i corelate my  Calendar.infodate  with the Employee. Start Date i won't be able to see people that they haven't changed not a single department for any future month except from their initial one.

 

Any suggstions would be appeciated,

Cheers

 

 

_Melenios__0-1625839348717.png

 

1 ACCEPTED SOLUTION

Hi @_Melenios_ ,

 

Sorry for the late reply.

Modify the measure as below:

Measure = 
var _mindate=CALCULATE(MIN('DIM_CALENDAR'[Date]),ALLSELECTED(DIM_CALENDAR))
var _maxdate=CALCULATE(MAX('DIM_CALENDAR'[Date]),ALLSELECTED(DIM_CALENDAR))
var maxdate=CALCULATE(MAX('DIM_CALENDAR'[Date]),ALL(DIM_CALENDAR))
var _end=IF(MAX('Table'[END])=BLANK(),maxdate,MAX('Table'[END]))
Return
IF(NOT(ISFILTERED(DIM_CALENDAR[Date])),DISTINCTCOUNT('Table'[EMPLOYEE]),CALCULATE(DISTINCTCOUNT('Table'[EMPLOYEE]),FILTER('Table',('Table'[START]<=_mindate&&_end>=_maxdate))))

And you will see:

vkellymsft_0-1627374545382.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

View solution in original post

11 REPLIES 11
_Melenios_
Helper I
Helper I

Hi @v-kelly-msft ,

 

Here you go :  https://easyupload.io/cjk7uu

 

Cheers!

Hi  @_Melenios_ ,

 

So do you wanna count the total number of employees during the selected period?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Hey @v-kelly-msft ,

 

Exactly. Picking up a random month and then being able to see where each employee is allocated(if applicable).

Hi @_Melenios_ ,

 

Delete the relationship between the two tables then create a measure as below:

Measure = 
var _mindate=CALCULATE(MIN('DIM_CALENDAR'[Date]),ALLSELECTED(DIM_CALENDAR))
var _maxdate=CALCULATE(MAX('DIM_CALENDAR'[Date]),ALLSELECTED(DIM_CALENDAR))
var maxdate=CALCULATE(MAX('DIM_CALENDAR'[Date]),ALL(DIM_CALENDAR))
var _end=IF(MAX('Table'[END])=BLANK(),maxdate,MAX('Table'[END]))
Return
CALCULATE(DISTINCTCOUNT('Table'[EMPLOYEE]),FILTER('Table',('Table'[START]<=_mindate&&_end>=_mindate)||('Table'[START]>=_mindate&&'Table'[START]<=_maxdate)))

And you will see:

vkellymsft_0-1626168621267.png

vkellymsft_1-1626168639207.png

For the related .pbix file,pls see attached.

 

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Dear @v-kelly-msft ,

 

Thank you for your prompt reply and solution. Even if your solution finds the allocations in between departments correct, the problem here is that if i select any other month (out of the start-end range) it still doesn't shows/sums correct how many people i have on each department.

 

 

Eg.1 :

By selecting the earliest hired employee(12.06) i should be able to see him repeating from June until the end of 2021 on the same department.

_Melenios__0-1626180273829.png

 

Eg.2 : If i pick up August i should be able to see the summary and the allocation only for August and so on.

 

_Melenios__1-1626180350916.png

_Melenios__2-1626181038375.png

 

 

Thank you

 

 

 

 

 

Hi  @_Melenios_ ,

 

Modify the measure as below:

Measure = 
var _mindate=CALCULATE(MIN('DIM_CALENDAR'[Date]),ALLSELECTED(DIM_CALENDAR))
var _maxdate=CALCULATE(MAX('DIM_CALENDAR'[Date]),ALLSELECTED(DIM_CALENDAR))
var maxdate=CALCULATE(MAX('DIM_CALENDAR'[Date]),ALL(DIM_CALENDAR))
var _end=IF(MAX('Table'[END])=BLANK(),maxdate,MAX('Table'[END]))
Return
CALCULATE(DISTINCTCOUNT('Table'[EMPLOYEE]),FILTER('Table',('Table'[START]<=_mindate&&_end>=_maxdate)))

And you will see:

vkellymsft_0-1626255260793.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Hey @v-kelly-msft ,

 

Thanks for the update.We're almost there i think. 🙂
The only problem i still have is that i want to visualise in my matrix not the start date from Employee Table but the months from the Calendar Table which i don't know how will happen since your measure did the trick but still when i'm selecting any month on the slicer i'm not able to reflect that on the matrix as well. 😞

Hi  @_Melenios_,

 

Not quite get what you mean.

My measure is based on the Calendar date:

Measure = 
var _mindate=CALCULATE(MIN('DIM_CALENDAR'[Date]),ALLSELECTED(DIM_CALENDAR))
var _maxdate=CALCULATE(MAX('DIM_CALENDAR'[Date]),ALLSELECTED(DIM_CALENDAR))

So could you pls provide your expected output for me to better understand your logic?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Hey @v-kelly-msft ,

 

So first thing is when you don't apply any filter your matrix is blank

_Melenios__0-1626330459444.png

And then what i really wanted is to apply the date from my DIM_Calendar to  the matrix and then being able to see each month my employees summary -allocations(if they're still working).

_Melenios__1-1626330668969.png

and desired output to be like below, correctly summing for each month selected(or all if no slicer is selected).

_Melenios__2-1626330743866.png

 

Thank you!

Hi @_Melenios_ ,

 

Sorry for the late reply.

Modify the measure as below:

Measure = 
var _mindate=CALCULATE(MIN('DIM_CALENDAR'[Date]),ALLSELECTED(DIM_CALENDAR))
var _maxdate=CALCULATE(MAX('DIM_CALENDAR'[Date]),ALLSELECTED(DIM_CALENDAR))
var maxdate=CALCULATE(MAX('DIM_CALENDAR'[Date]),ALL(DIM_CALENDAR))
var _end=IF(MAX('Table'[END])=BLANK(),maxdate,MAX('Table'[END]))
Return
IF(NOT(ISFILTERED(DIM_CALENDAR[Date])),DISTINCTCOUNT('Table'[EMPLOYEE]),CALCULATE(DISTINCTCOUNT('Table'[EMPLOYEE]),FILTER('Table',('Table'[START]<=_mindate&&_end>=_maxdate))))

And you will see:

vkellymsft_0-1627374545382.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

v-kelly-msft
Community Support
Community Support

Hi  @_Melenios_ ,

 

Could you pls provide an expected output based on your sample data ?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

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.