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

Basic Data Modeling Question

I am fairly new to PBI, so forgive me if this is a simple question.

 

I have a data set that looks something like this: 

Data Set.jpg

 

I am trying to create a basic line chart that shows the 'Month - Year' as the X Axis and counts both the number of new hires and terminations for that month on the Y Axis (2 different lines).  I also need to be able to create filters based on other data in the dataset such as Department, Manager etc. (not shown).  I've tried this several ways including separating out the termination data from the hire data, and linking them through a separate 'Month - Year' table which contains all unique values for month - year.  This works for showing the two lines in the visualization, but it won't allow me to filter by Manager, Department etc. correctly.  

 

If I keep all the data in one table it's not letting me link both the Hire Month - Year and the Termination Month - Year fields to the 'Month - Year' table.  So, it's the opposite problem - I can sort by Manager/Department just fine, but the data is not showing up correctly in the chart.

 

Any help would be much appreciated.

 

Thanks

1 ACCEPTED SOLUTION
AkhilAshok
Solution Sage
Solution Sage

You can easily do this the following way:

 

1. Create a Date table with below logic and sort Year Month & Month based on the respective Number columns:

Date =
VAR BaseCalendar =
    CALENDAR (
        MIN ( Table[Hire Date], Table[Termination Date] ),
        MAX ( Table[Hire Date], Table[Termination Date] )
    )
RETURN
    GENERATE (
        BaseCalendar,
        VAR BaseDate = [Date]
        VAR YearDate =
            YEAR ( BaseDate )
        VAR MonthNumber =
            MONTH ( BaseDate )
        VAR YearMonthNumber = YearDate * 12 + MonthNumber - 1
        RETURN
            ROW (
                "Year", YearDate,
                "Month Number", MonthNumber,
                "Month", FORMAT ( BaseDate, "mmmm" ),
                "Year Month Number", YearMonthNumber,
                "Year Month", FORMAT ( BaseDate, "m-yyyy" )
            )
    )

2. Create 2 Relationships from Date[Date] to Table[Hire Date] & Table[Termination Date]. One relationship will be automatically marked Inactive.

 

3. Create the following 2 measures (assuming Termination Date relationship is marked Inactive):

Hired Employee # =
DISCTINCTCOUNT(Table[Employee])

Terminated Employee # =
CALCULATE (
    DISTINCTCOUNT ( Table[Employee] ),
    USERELATIONSHIP ( Table[Termination Date], Date[Date] )
)

4. Create a line chart between Date[Year Month] & the 2 Measures.

 

Hope this helps.

View solution in original post

4 REPLIES 4
AkhilAshok
Solution Sage
Solution Sage

You can easily do this the following way:

 

1. Create a Date table with below logic and sort Year Month & Month based on the respective Number columns:

Date =
VAR BaseCalendar =
    CALENDAR (
        MIN ( Table[Hire Date], Table[Termination Date] ),
        MAX ( Table[Hire Date], Table[Termination Date] )
    )
RETURN
    GENERATE (
        BaseCalendar,
        VAR BaseDate = [Date]
        VAR YearDate =
            YEAR ( BaseDate )
        VAR MonthNumber =
            MONTH ( BaseDate )
        VAR YearMonthNumber = YearDate * 12 + MonthNumber - 1
        RETURN
            ROW (
                "Year", YearDate,
                "Month Number", MonthNumber,
                "Month", FORMAT ( BaseDate, "mmmm" ),
                "Year Month Number", YearMonthNumber,
                "Year Month", FORMAT ( BaseDate, "m-yyyy" )
            )
    )

2. Create 2 Relationships from Date[Date] to Table[Hire Date] & Table[Termination Date]. One relationship will be automatically marked Inactive.

 

3. Create the following 2 measures (assuming Termination Date relationship is marked Inactive):

Hired Employee # =
DISCTINCTCOUNT(Table[Employee])

Terminated Employee # =
CALCULATE (
    DISTINCTCOUNT ( Table[Employee] ),
    USERELATIONSHIP ( Table[Termination Date], Date[Date] )
)

4. Create a line chart between Date[Year Month] & the 2 Measures.

 

Hope this helps.

Anonymous
Not applicable

This worked perfectly.  Thanks so much for the help!

Anonymous
Not applicable

Did you create a COUNT( ) measure for both Terminations and Hires? Seem like that is what you are missing. The chart will not count for you. Make the COUNT measures and bring those into the chart.

 

If the filters you said did not woirk in the chart work in the table then it's the measures. If the filters do not work in the table then you have a connection issue: the tables are not linked properly.  

 

Anonymous
Not applicable

Thanks for the response.

 

So, in the case you are suggesting I'm guessing I'd build Measures to count the Hires/Terminations by Month - Year.  I'm thinking I would need to create a measure for each unique Month - Year value...?  Is that right?  If so, what field do I use as the X Axis on the line chart?

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.