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.
Hi all,
I am still discovering DAX and I am incredibly grateful for the support of this forum so far. I have a problem I dont know why i am not getting an output for just a few of the values. I can really use your help!
I have the following DAX:
Position From (Year) = IF('Ordinary Hours'[Calculation Date].[Date] < DATEADD('Ordinary Hours'[Position From Date].[Date],1,YEAR), "Y1",
IF('Ordinary Hours'[Calculation Date].[Date] < DATEADD('Ordinary Hours'[Position From Date].[Date],2,YEAR), "Y2",
IF('Ordinary Hours'[Calculation Date].[Date] < DATEADD('Ordinary Hours'[Position From Date].[Date],3,YEAR), "Y3",
IF('Ordinary Hours'[Calculation Date].[Date] < DATEADD('Ordinary Hours'[Position From Date].[Date],4,YEAR), "Y4",
IF('Ordinary Hours'[Calculation Date].[Date] < DATEADD('Ordinary Hours'[Position From Date].[Date],5,YEAR), "Y5",
IF('Ordinary Hours'[Calculation Date].[Date] < DATEADD('Ordinary Hours'[Position From Date].[Date],6,YEAR), "Y6",
IF('Ordinary Hours'[Calculation Date].[Date] < DATEADD('Ordinary Hours'[Position From Date].[Date],7,YEAR), "Y7",
IF('Ordinary Hours'[Calculation Date].[Date] < DATEADD('Ordinary Hours'[Position From Date].[Date],8,YEAR), "Y8",
IF('Ordinary Hours'[Calculation Date].[Date] < DATEADD('Ordinary Hours'[Position From Date].[Date],9,YEAR), "Y9",
"NA")))))))))
The columns are date time columns as below:
I am getting NA as output for these values when it should be "Y1"
What am I doing wrong here? or is DAX calculating it incorrectly?
@Ashish_Mathur @danextian @amitchandak @Greg_Deckler @PaulDBrown @ImkeF @MFelix
Thanks,
Harshad
Solved! Go to Solution.
Hi @harshad_barge ,
If you are simply trying to get the difference in years between two dates, you can just use DATEDIFF().
Position from (Year) =
DATEDIFF ( 'Table'[Calculation Date], 'Table'[Position From Date], YEAR )
Proud to be a Super User!
create a datediff column in year and month and the use switch true(). Both as column
diff = datediff('Ordinary Hours'[Calculation Date],'Ordinary Hours'[Position From Date],Year)
switch(true(),
diff < 1, "Y1",
diff < 2, "Y2",
diff < 3, "Y3",
diff < 4, "Y4",
diff < 5, "Y5",
diff < 6, "Y6",
diff < 7, "Y7",
diff < 8, "Y8",
diff < 9, "Y9",
"Y10")
Hi @harshad_barge ,
If you are simply trying to get the difference in years between two dates, you can just use DATEDIFF().
Position from (Year) =
DATEDIFF ( 'Table'[Calculation Date], 'Table'[Position From Date], YEAR )
Proud to be a Super User!
If the date does not have a timestamp. Remove .date
Hi,
Write this calculated column formula
=IF('Ordinary Hours'[Calculation Date] < DATEADD('Ordinary Hours'[Position From Date],1,YEAR),"Y1",BLANK())
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
99 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
102 | |
87 | |
64 |