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 really close to my desired outcome, but need to figure out a small change. I have a product that expires after two years. I have data on the order date, so I made a column called "Expiration Date" which is simply two years after the order date.
I created this coding:
Solved! Go to Solution.
@Dehlilah So, a few possible improvements:
Expiration Category v2 =
SWITCH(TRUE(),
( TODAY() - [Expiration Date] ) * 1. < 0, "Expired",
( TODAY() - [Expiration Date] ) * 1. <= 30, "Expires in 30 days",
( TODAY() - [Expiration Date] ) * 1. <= 60, "Expires in 60 days",
"Expires in 180+ days"
)
So, SWITCH(TRUE(), ...) is much cleaner than nested IF statements. Two, using simple math keeps the computation out of the formula engine which is faster. Dates are the number of days since December 30th, 1899 so you can just use subtraction to get the number of days.
Depending on your data, you may want to reverse your logic. If the majority of the items are 180+ from expiring then you will want that condition first in your SWITCH statement for example. That way the majority of rows do not have to fail a bunch of other logical conditions before getting to the right one.
@Dehlilah So, a few possible improvements:
Expiration Category v2 =
SWITCH(TRUE(),
( TODAY() - [Expiration Date] ) * 1. < 0, "Expired",
( TODAY() - [Expiration Date] ) * 1. <= 30, "Expires in 30 days",
( TODAY() - [Expiration Date] ) * 1. <= 60, "Expires in 60 days",
"Expires in 180+ days"
)
So, SWITCH(TRUE(), ...) is much cleaner than nested IF statements. Two, using simple math keeps the computation out of the formula engine which is faster. Dates are the number of days since December 30th, 1899 so you can just use subtraction to get the number of days.
Depending on your data, you may want to reverse your logic. If the majority of the items are 180+ from expiring then you will want that condition first in your SWITCH statement for example. That way the majority of rows do not have to fail a bunch of other logical conditions before getting to the right one.
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 |
---|---|
11 | |
11 | |
10 | |
9 | |
8 |
User | Count |
---|---|
17 | |
12 | |
11 | |
11 | |
11 |