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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

If statement for a calculated column

Hi,

 

I have a column added into my table which is using a datediff that says how many days between 2 dates ,

Age =datediff('Table1'[Date A],'Table 1'[Date 2],DAY)

 

However I am trying to create something that will say If the above Age column is over 7 days then use 7 (to sort of set 7 as a max value) and if the age is under 7 continue to use the original column, but nothing seems to be working!

 

As the datediff has been created in the table and doesn't appear in the advanced editor I can't do it as a conditional column.

 

One of the conditional columns I have used column doing something similar has something that would translate like this 

 

Test =IF [#"Age"] > 7.001,then "7" else [#"Age"]) 

 

But that didn't work.

 

Any help would be appreciated.

 

Thanks

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @Anonymous 

if you use DAX calculated column your new column will look like

Test = MIN([Age], 7) 

you also can use this technique

Age = 
var _dd = datediff('Table1'[Date A],'Table 1'[Date 2],DAY)
RETURN 
IF(_dd < 7, 7, _dd)

  


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , for one, is DAX, the second one is M?

Try

Age =
var _1 = datediff('Table1'[Date A],'Table 1'[Date 2],DAY)
return
if(_1>7,7,_1)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
az38
Community Champion
Community Champion

Hi @Anonymous 

if you use DAX calculated column your new column will look like

Test = MIN([Age], 7) 

you also can use this technique

Age = 
var _dd = datediff('Table1'[Date A],'Table 1'[Date 2],DAY)
RETURN 
IF(_dd < 7, 7, _dd)

  


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

The first one seems to have worked perfectly, thank you.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors