Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
Hallo zusammen,
ich habe folgende Problematik.
Ich habe eine Tabelle in der zu jedem Mitarbeiter eine Spalte mit dem Hire Date und dem Exit Date (falls vorhanden - ansonsten leer) existiert.
Nun soll er mir in einer berechneten Spalte die Duration als ganze Zahl anzeigen. Hier ist aber das Problem das er immer ein Jahr zu viel nimmt. Sprich ein Mitarbeiter ist 103 Monate also ca. 8,6 Jahre da, dann soll er mir als Dauer 8 anzeigen, da er das neunte Jahr noch nicht vollendet hat.
Folgenden Code habe ich in den zwei Berechneten Spalten:
Solved! Go to Solution.
Hallo @PleinCiel,
Entschuldigen Sie bitte, aber ich musste die Übersetzung nach Deutschland schicken. Bitte ignorieren Sie Rechtschreibfehler.
Ich habe hier eine Situation mit den Daten simuliert und das Notwendige in eine berechnete Spalte eingegeben, um das Verständnis zu erleichtern. Sagen Sie mir bitte, ob Sie dies verwenden oder eine herkömmliche Methode.
Employment Duration (Years) =
VAR StartDate = 'tbl_Employees'[Hire Date]
VAR EndDate =
IF(
ISBLANK('tbl_Employees'[Exit Date]),
DATE(YEAR(TODAY()), 12, 31),
'tbl_Employees'[Exit Date]
)
RETURN
INT(DATEDIFF(StartDate, EndDate, MONTH) / 12)tbl_Employees:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PY5BCsIwEEWvErKuZCZpbbuU7kRBdBm6CDSLQEgkrV7Io3gxZ6K4fMObx7dWomzkITlxdmULaSXCToFRGrAjAFSoCbSRc2OlptMxv19Z3EJ8uq8APdsDQXrEWD1DcA0bZX1aPFcpATtAgUBgQCFyVVe7pdPFLyWLKa9brdKGkas9vw4K6oa22jxrciU6ccr3X1vBnu3xv2H+AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [EmployeelD = _t, Nome = _t, #"Hire Date" = _t, #"Exit Date" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Hire Date", type date}, {"Exit Date", type date}})
in
#"Changed Type"
✅Wenn diese Antwort Ihr Problem gelöst hat, markieren Sie sie bitte als korrekt, um anderen Mitgliedern der Community zu helfen.
If this response was helpful in any way, I’d gladly accept a kudo.
Please mark it as the correct solution. It helps other community members find their way faster.
Connect with me on LinkedIn
Hi @PleinCiel,
I've used Google translate to answer your query as i don't know german, any spelling mistakes should be ignored,
Der Fehler bei der Jahresberechnung entsteht dadurch, dass die Differenz in Jahren und nicht in Tagen berechnet wird.
Siehe folgendes Beispiel:
DATEDIFF("2016-12-31", "2017-01-01", YEAR)
In diesem Beispiel gibt DAX trotz eines vergangenen Tages ein Jahr zurück, da sich das Jahr geändert hat. Versuchen Sie es mit folgendem DAX-Ausdruck:Employment Duration =
VAR HireDate = 'tbl_Employees'[Hire Date]
VAR ExitDate =
COALESCE('tbl_Employees'[Exit Date], TODAY())
VAR FullYears = DATEDIFF(HireDate, ExitDate, YEAR)
VAR AnniversaryThisYear =
DATE(YEAR(ExitDate), MONTH(HireDate), DAY(HireDate))
RETURN
IF(ExitDate < AnniversaryThisYear, FullYears - 1, FullYears)
🌟 I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
💡 Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
🎖 As a proud SuperUser and Microsoft Partner, we’re here to empower your data journey and the Power BI Community at large.
🔗 Curious to explore more? [Discover here].
Let’s keep building smarter solutions together!
Hallo @PleinCiel,
Entschuldigen Sie bitte, aber ich musste die Übersetzung nach Deutschland schicken. Bitte ignorieren Sie Rechtschreibfehler.
Ich habe hier eine Situation mit den Daten simuliert und das Notwendige in eine berechnete Spalte eingegeben, um das Verständnis zu erleichtern. Sagen Sie mir bitte, ob Sie dies verwenden oder eine herkömmliche Methode.
Employment Duration (Years) =
VAR StartDate = 'tbl_Employees'[Hire Date]
VAR EndDate =
IF(
ISBLANK('tbl_Employees'[Exit Date]),
DATE(YEAR(TODAY()), 12, 31),
'tbl_Employees'[Exit Date]
)
RETURN
INT(DATEDIFF(StartDate, EndDate, MONTH) / 12)tbl_Employees:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PY5BCsIwEEWvErKuZCZpbbuU7kRBdBm6CDSLQEgkrV7Io3gxZ6K4fMObx7dWomzkITlxdmULaSXCToFRGrAjAFSoCbSRc2OlptMxv19Z3EJ8uq8APdsDQXrEWD1DcA0bZX1aPFcpATtAgUBgQCFyVVe7pdPFLyWLKa9brdKGkas9vw4K6oa22jxrciU6ccr3X1vBnu3xv2H+AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [EmployeelD = _t, Nome = _t, #"Hire Date" = _t, #"Exit Date" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Hire Date", type date}, {"Exit Date", type date}})
in
#"Changed Type"
✅Wenn diese Antwort Ihr Problem gelöst hat, markieren Sie sie bitte als korrekt, um anderen Mitgliedern der Community zu helfen.
If this response was helpful in any way, I’d gladly accept a kudo.
Please mark it as the correct solution. It helps other community members find their way faster.
Connect with me on LinkedIn
Vielen Dank für die Hilfe.
Hallo @PleinCiel ,
um das genau zu verstehen wäre es spannend zu wissen, welcher Datentyp den Spalten zugeordnet ist. DATEDIFF liefert eine Dezimalzahl. An irgendeiner Stelle erfolgt dann offenbar eine Rundung. Um sicher zu gehen, dass das gewünschte passiert, wäre es hier sinnvoll direkt in der Formel eine entsprechende Anpassung vorzunehmen. Das wäre dann vermutlich in INT() um den DATEDIFF Ausdruck. Damit ist klar, dass immer abgerundet werden soll auf die nächste ganze Zahl.
Hoffe ich habe das Problem richtig verstanden und konnte helfen...
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 48 | |
| 46 | |
| 41 | |
| 20 | |
| 17 |
| User | Count |
|---|---|
| 70 | |
| 69 | |
| 32 | |
| 27 | |
| 26 |