Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
rafamorim87
Frequent Visitor

Datediff Probleam

Goodnight

I would like some help, I have a database that has employee names and their hire dates. I created the formula to calculate company time based on the date entered in the filter.
I created the formula in the image, but when I put it on the graph, it is not showing the values. See image below Could anyone give me some more help, please?

 

duvida.jpg

2 ACCEPTED SOLUTIONS
RossEdwards
Solution Specialist
Solution Specialist

Change your vLastDate to:

CALCULATE(LASTDATE(dimCalendario[Data]), ALLSELECTED(dimCalendario))

 

The problem is that your date context in your table means "LastDate" is currently giving you the last date of that year, which will always be a datediff of 0.

View solution in original post

Best practise is to model your data in a Star Schema.  I would suggest adding to your model a "Person" table, that contains 1 row per person. Then use a unique ID to create a relationship between your person table and the data table.  When building your visuals, use the Person table's fields on your report. When using the measure, this will constrain your measure to run once for each person.

 

To creature an average, we'll use the Average iterator function.  I'll assume you have a person table for my example:

Average Example = AVERAGEX(
    VALUES('People'[Person Name]),
    [Tempo de Empresa]
)

View solution in original post

4 REPLIES 4
v-yilong-msft
Community Support
Community Support

Hi @rafamorim87 ,

As you show the DAX code on the image, I noticed that you are using the DATEDIFF function, but it is used to return the number of boundaries of the interval between two dates. Here it is using YEAR, so it will also only show 0 between two neighboring years and the final Total is 4.

vyilongmsft_0-1712021337346.png

You can check this documentation below: DATEDIFF function (DAX) - DAX | Microsoft Learn

 

 

 

Best Regards

Yilong Zhou

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

RossEdwards
Solution Specialist
Solution Specialist

Change your vLastDate to:

CALCULATE(LASTDATE(dimCalendario[Data]), ALLSELECTED(dimCalendario))

 

The problem is that your date context in your table means "LastDate" is currently giving you the last date of that year, which will always be a datediff of 0.

Thank you very much. I managed to solve it. Now I need just one more help, if I can. 1 - I would like to know how I can group the number of employees according to this measure I created. 2- How can I calculate the average of this measurement I created Thank you again in advance

 

duvida 2.jpg

Best practise is to model your data in a Star Schema.  I would suggest adding to your model a "Person" table, that contains 1 row per person. Then use a unique ID to create a relationship between your person table and the data table.  When building your visuals, use the Person table's fields on your report. When using the measure, this will constrain your measure to run once for each person.

 

To creature an average, we'll use the Average iterator function.  I'll assume you have a person table for my example:

Average Example = AVERAGEX(
    VALUES('People'[Person Name]),
    [Tempo de Empresa]
)

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.