Multiple IF conditions in PowerBI to see if the date falls within Date Range

Viewed 36

I need to create a condition where my start date for last year is 3/14/2021 and end date is 11/14/2021 and For this year 3/13/2021 and end date is 11/13/2021. What ever the date falls with in this range should be true else False

I have list of dates where i need to see if the dates fall within the above mentioned range

List of dates 2/6/2021 6/6/2021 1/3/2022 9/8/2022 11/19/2022

I need a result as MM/DD/YYYY

2/6/2021 - False 6/6/2021 - True 1/3/2022 - False 9/8/2022 - True 11/19/2022 - False

2 Answers

9/8/2022 is not in the range 3/13/2021 through 11/13/2021, so no idea why that should be true, but in general the format in M/PowerQuery is below, assuming the test column is named date

#"Added Custom" = Table.AddColumn(#"PriorStepNameGoesHere", "CheckDate", each if [date]>=#date(2021,3,13) and [date]<=#date(2021,11,13) then true else false)

or potentially two date ranges

 #"Added Custom" = Table.AddColumn(#"PriorStepNameGoesHere", "CheckDate", each
    if [date]>=#date(2021,3,14) and [date]<=#date(2021,11,14) then true
    else if [date]>=#date(2022,3,13) and [date]<=#date(2022,11,13) then true
    else false)

In DAX you should try something like this:

IF(
    (SELECTEDVALUE() >= "3/14/2021" AND SELECTEDVALUE() <= "11/14/2021")
        || (SELECTEDVALUE() >= "3/13/2022" AND SELECTEDVALUE() <= "11/13/2022"),
    SELECTEDVALUE(),
    BLANK()
)

This formula will work on report panel. Let me know if you want to use in on data panel - I will correct my answer.

Related