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
leazimmer
Frequent Visitor

Calculation the age between today and birthday

Hello together,

 

i need your help 🙂

My Report need the age from the customer, but i get always a error i don't know why.

Geburtstag and heute is a date Format

This my DAX-Query 1

if
(Date.Year([Heute]) - Date.Year([Geburtstag])
- (if Date.Month([Heute]) < Date.Month([Geburtstag]) then 1 else
if Date.Month([Heute]) = Date.Month([Geburtstag]) and Date.Day([Heute]) < Date.Day([Geburtstag]) then 1 else 0)) < 0 then null
else
Date.Year([Heute]) - Date.Year([Geburtstag]) -
(if Date.Month([Heute]) < Date.Month([Geburtstag]) then 1 else
if Date.Month([Heute]) = Date.Month([Geburtstag]) and Date.Day([Heute]) < Date.Day([Geburtstag]) then 1 else 0))

Secand Query:

Alter =
VAR varAlter =
Year(TODAY())
- Year('konzeptum'[Geburtag])
-(
IF(
Month(TODAY()) < Month([Geburtstag]),
1,
IF(
AND(Month(TODAY()) = Month([Geburtstag]), Day(TODAY()) < Day([Geburtstag]))
,1,
0)
)
)

RETURN
IF([Geburtstag]=BLANK(),
BLANK(),
IF(varAlter <0,BLANK(), varAlter)
)
The error message is, that not found the field "Geburtstag" but this is a date field.
 
Thanks for your help
Lea

 

1 ACCEPTED SOLUTION

@leazimmer , if this is measure then

Age = datediff( max('konzeptum'[Geburtstag]), today(), year)

 

and you need row context

sumx('konzeptum', datediff('konzeptum'[Geburtstag], today(), year))

or

AverageX('konzeptum', datediff('konzeptum'[Geburtstag], today(), year))

 

or

Sumx(Values('konzeptum'[Kustomer]), calculate(datediff( max('konzeptum'[Geburtstag]), today(), year) ))

View solution in original post

3 REPLIES 3
leazimmer
Frequent Visitor

I get a error message

Age = datediff('konzeptum'[Geburtstag], today(), year)
Problem with the aggregation 

@leazimmer , if this is measure then

Age = datediff( max('konzeptum'[Geburtstag]), today(), year)

 

and you need row context

sumx('konzeptum', datediff('konzeptum'[Geburtstag], today(), year))

or

AverageX('konzeptum', datediff('konzeptum'[Geburtstag], today(), year))

 

or

Sumx(Values('konzeptum'[Kustomer]), calculate(datediff( max('konzeptum'[Geburtstag]), today(), year) ))

amitchandak
Super User
Super User

@leazimmer , You can create new columns

example 

Age = datediff([Geburtstag ], today(), year)

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.