Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I am brand new to DAX. In one of my lessons I was told to enter an IF statement:
Solved! Go to Solution.
Hello @revisr,
If statement syntax is IF(<logical_test>, <value_if_true>[, <value_if_false>])
IF function (DAX) - DAX | Microsoft Learn
Therefore, you code should be like this:
IF(
FORMAT('Customer'[Birth Date], "mmdd") <= FORMAT(TODAY(), "mmdd"),
DATEDIFF('Customer'[Birth Date], TODAY(), YEAR),
IF(
FORMAT('Customer'[Birth Date], "mmdd") > FORMAT(TODAY(), "mmdd"),
DATEDIFF('Customer'[Birth Date], TODAY(), YEAR),
1
)
)
Best Regards,
Gökberk Uzuntaş
LinkedIn: https://www.linkedin.com/in/g%C3%B6kberk-uzunta%C5%9F-b43906198/
Medium: https://medium.com/@uzuntasgokberk
İf this post helps, then please consider Accept it as solution and kudos to help the other members find it more quickly.
That did it thanks!!
Hi revisr,
Looks like the formula @uzuntasgokberk provided was unnecessarily complex. You were on the right track with your original measure. You just had an extra comma in your measure, before the -1 at the end. The comma made Power BI think the -1 was a fourth argument in your IF function. Hopefully that makes sense.
You had:
IF (
FORMAT ( 'Customer'[Birth Date], "mmdd" ) <= FORMAT ( TODAY(), "mmdd" ),
DATEDIFF ( 'Customer'[Birth Date], TODAY(), YEAR ),
DATEDIFF ( 'Customer'[Birth Date], TODAY(), YEAR ), - 1
)
However, what you meant was:
IF (
FORMAT ( 'Customer'[Birth Date], "mmdd" ) <= FORMAT ( TODAY(), "mmdd" ),
DATEDIFF ( 'Customer'[Birth Date], TODAY(), YEAR ),
DATEDIFF ( 'Customer'[Birth Date], TODAY(), YEAR ) - 1
)
Proud to be a Super User! | |
Hello @revisr,
If statement syntax is IF(<logical_test>, <value_if_true>[, <value_if_false>])
IF function (DAX) - DAX | Microsoft Learn
Therefore, you code should be like this:
IF(
FORMAT('Customer'[Birth Date], "mmdd") <= FORMAT(TODAY(), "mmdd"),
DATEDIFF('Customer'[Birth Date], TODAY(), YEAR),
IF(
FORMAT('Customer'[Birth Date], "mmdd") > FORMAT(TODAY(), "mmdd"),
DATEDIFF('Customer'[Birth Date], TODAY(), YEAR),
1
)
)
Best Regards,
Gökberk Uzuntaş
LinkedIn: https://www.linkedin.com/in/g%C3%B6kberk-uzunta%C5%9F-b43906198/
Medium: https://medium.com/@uzuntasgokberk
İf this post helps, then please consider Accept it as solution and kudos to help the other members find it more quickly.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
8 | |
8 | |
7 |
User | Count |
---|---|
13 | |
12 | |
11 | |
11 | |
8 |