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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Vatz8
Helper I
Helper I

Using if statement with date condition to choose between two measures in different tables.

Hi,

I have two measures in two different table lets say Table 1 and Table 2. I have created a matrix table with Table 1 - Measure as value field. However, now we have received a data table (Table 2) which is similar to the previous one  and I have created measures similar to the previous table measures i.e. Table 2- Measure 2.

 

I need to add this measure to the same data matrix but the condition is that if the date is >01/20/2023 then I have to select Measure 2 and if it is before 01/20/2023 then the matrix selects Measure 1. I tried using simple if statement but it does not work as the condition part does not take date column it only takes measures.

 

Please let me know if there is a solution here.I cannot merge the two tables because even if they are similar they are not exactly the same.So will need to keep the two tables seperate.

 

Thank you in Advance.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Vatz8 ,

 

According to your statement, I think there should be both [Date] columns in 'Table 1' and 'Table 2'. Here I suggest you to create a DimDate table by CALENDAR() or CALENDARAUTO() function.

RicoZhou_0-1674802837668.png

Table1:

RicoZhou_1-1674802875772.png

Table2:

RicoZhou_2-1674802883149.png

Measure:

Measure = 
VAR _ADD =
    ADDCOLUMNS (
        DimDate,
        "IF",
            VAR _DATE =
                DATE ( 2023, 01, 20 )
            RETURN
                IF ( DimDate[Date] > _DATE, [Measure 2], [Measure 1] )
    )
RETURN
    SUMX ( _ADD, [IF] )

Result is as below.

RicoZhou_3-1674803019661.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Vatz8 ,

 

According to your statement, I think there should be both [Date] columns in 'Table 1' and 'Table 2'. Here I suggest you to create a DimDate table by CALENDAR() or CALENDARAUTO() function.

RicoZhou_0-1674802837668.png

Table1:

RicoZhou_1-1674802875772.png

Table2:

RicoZhou_2-1674802883149.png

Measure:

Measure = 
VAR _ADD =
    ADDCOLUMNS (
        DimDate,
        "IF",
            VAR _DATE =
                DATE ( 2023, 01, 20 )
            RETURN
                IF ( DimDate[Date] > _DATE, [Measure 2], [Measure 1] )
    )
RETURN
    SUMX ( _ADD, [IF] )

Result is as below.

RicoZhou_3-1674803019661.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Wheezy
Regular Visitor

What if you try the next measure:

 

IF(

SELECTEDVALUE([Date_Column]) > DATE(2023, 01, 20),

[Measure2],

[Measure1]

)

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.