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

Join 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.

Reply
Nini1
Frequent Visitor

Creating Column/Measure depending on variables

Hello everyone,

 

It's not been a long time I'm using Power Bi and need your help to solve this issue.

 

I have the following  data 

IDID2Date1Date2
129/29/202110/30/2021
239/30/202110/30/2021
2410/5/202110/30/2021
31010/5/202111/15/2021
31310/8/202111/15/2021
31511/2/202111/15/2021
4231/31/20215/1/2021
4242/2/20215/1/2021

 

I want to create a column which will be equal to date2 but in specific time period - values that are more then min value of date1 and less than max value of date1. 

 

To clarify, I tried with the formula below. 

 

Time Period = 
VAR MIN_P_ = MIN('Tbl'[Date1])
VAR MAX_P_ = MAX('Tbl'[Date1])
VAR Time_Per = MIN_P_<='Tbl'[Date2]<= MAX_P_
return Time_Per

 

 Just this does not work,it gives me this error: DAX comparison operations do not support comparing values of type True/False with values of type Date. Consider using the VALUE or FORMAT function to convert one of the values.

 

Could you please help to transform and adjust the formula above so that I could get a desired result?

 

Thank you in advance

1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

Hi @Nini1 ,

 

You can try below code:-

Time Period =
VAR MIN_P_ =
    CALCULATE ( MIN ( 'Dates_range'[Date1] ), ALL ( Dates_range ) )
VAR MAX_P_ =
    CALCULATE ( MAX ( 'Dates_range'[Date1] ), ALL ( Dates_range ) )
VAR Time_Per =
    IF (
        AND ( 'Dates_range'[Date2] >= MIN_P_, 'Dates_range'[Date2] <= MAX_P_ ),
        Dates_range[Date2]
    )
RETURN
    Time_Per

Ouput:-

Samarth_18_0-1641824708032.png

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

3 REPLIES 3
Samarth_18
Community Champion
Community Champion

Hi @Nini1 ,

 

You can try below code:-

Time Period =
VAR MIN_P_ =
    CALCULATE ( MIN ( 'Dates_range'[Date1] ), ALL ( Dates_range ) )
VAR MAX_P_ =
    CALCULATE ( MAX ( 'Dates_range'[Date1] ), ALL ( Dates_range ) )
VAR Time_Per =
    IF (
        AND ( 'Dates_range'[Date2] >= MIN_P_, 'Dates_range'[Date2] <= MAX_P_ ),
        Dates_range[Date2]
    )
RETURN
    Time_Per

Ouput:-

Samarth_18_0-1641824708032.png

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

@Samarth_18  Thank you very much and should I change it when e.g. Date2 is from another table? I should write the code differently, right?

Samarth_18
Community Champion
Community Champion

@Nini1 I think it should work in that case as well.

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.