This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
Hi Power BI Experts,
I want to calculate condition column based on the date time field will fall in between, before & after conditions. Sample data below. Expected output in "condition" column. Please provide the dax expression. I tried the below dax code but it doesn't given correct output what i am looking. Thanks in advance.
| Date Time | From Date Time | To Date Time | ID | Condition |
| 11/16/2020 0:01 | 11/16/2020 0:00 | 11/18/2020 0:00 | 6107 | With In Range |
| 7/9/2020 14:45 | 7/10/2020 0:00 | 7/15/2020 0:00 | 3734 | Before Range |
| 3/7/2020 22:00 | 3/7/2020 0:00 | 3/17/2020 0:00 | 1478 | With In Range |
| 11/8/2020 1:52 | 10/27/2020 0:00 | 11/4/2020 0:00 | 5717 | After Range |
| 4/16/2020 15:30 | 4/12/2020 0:00 | 4/22/2020 0:00 | 2039 | With In Range |
| 5/31/2020 3:47 | 6/1/2020 12:00 | 6/5/2020 12:00 | 2834 | Before Range |
Dax Expression:
Condition =
vAR _DATE='Date Time'[Date Time]
var _With_In=COUNTROWS(FILTER('Date Time','Date Time'[From Date Time]<=_DATE && 'Date Time'[To Date Time]>=_DATE))
var _Before=COUNTROWS(FILTER('Date Time','Date Time'[From Date Time]<='Date Time'[Date Time]))
var _After=COUNTROWS(FILTER('Date Time','Date Time'[To Date Time]>=_DATE))
RETURN
IF(_With_In=1,"With in",IF(_After=1,"After",IF(_Before=1,"Before")))
Solved! Go to Solution.
Right click on the table and add "New Column". Use below DAX (Modify the table name).
Condition =
VAR DateTimeValue = 'Table_name'[Date Time]
VAR FromDateTimeValue = 'Table_name'[From Date Time]
VAR ToDateTimeValue = 'Table_name'[To Date Time]
RETURN
SWITCH(
TRUE(),
DateTimeValue >= FromDateTimeValue && DateTimeValue <= ToDateTimeValue, "With In Range",
DateTimeValue < FromDateTimeValue, "Before Range",
DateTimeValue > ToDateTimeValue, "After Range"
)
Right click on the table and add "New Column". Use below DAX (Modify the table name).
Condition =
VAR DateTimeValue = 'Table_name'[Date Time]
VAR FromDateTimeValue = 'Table_name'[From Date Time]
VAR ToDateTimeValue = 'Table_name'[To Date Time]
RETURN
SWITCH(
TRUE(),
DateTimeValue >= FromDateTimeValue && DateTimeValue <= ToDateTimeValue, "With In Range",
DateTimeValue < FromDateTimeValue, "Before Range",
DateTimeValue > ToDateTimeValue, "After Range"
)
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 6 | |
| 6 | |
| 6 | |
| 5 | |
| 4 |