简体   繁体   中英

PowerPivot DAX formula if then for dates

I have a column named ExpireDate in my PowerPivot table (not PowerBI) and want to make another column based on the value of Today's Date - ExpireDate with a DAX formula like below:

=if(Format([ExpireDate] -today(), "General Number") <= 90, "Less than 3 months", 
 if(90 < Format( [ExpireDate] -today() ,"General Number") <= 180, " 3 to 6 months", 
 if([Format (ExpireDate]-today() ,"General Number") > 180, "More than 6 months","Other"))

But this formula keeps showing error messages, saying it needs a proper formula. Anybody knows how to deal with this problem? Thanks a lot.

Assuming you are using Excel 2016, and your table name is "Table":

=
VAR Expiration = Table[ExpireDate] - TODAY ()
RETURN
    SWITCH (
        TRUE (),
        Expiration <= 90, "Less than 3 months",
        Expiration <= 180, " 3 to 6 months",
        Expiration > 180, "More than 6 months",
        "Other"
    )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM