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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Help With Date

Hi all,

 

I'm trying to compare a date measure with a date in my data table.  The date measure I have is:

 

IF(CALCULATE(SUM(YieldDataTable[RunQuantity]), FILTER(YieldDataTable,YieldDataTable[RunDate].[Date]=TODAY()))>100, TODAY(),
IF(CALCULATE(SUM(YieldDataTable[RunQuantity]), FILTER(YieldDataTable,YieldDataTable[RunDate].[Date]=TODAY()-1))>100, TODAY()-1,
IF(CALCULATE(SUM(YieldDataTable[RunQuantity]), FILTER(YieldDataTable,YieldDataTable[RunDate].[Date]=TODAY()-2))>100, TODAY()-2,
IF(CALCULATE(SUM(YieldDataTable[RunQuantity]), FILTER(YieldDataTable,YieldDataTable[RunDate].[Date]=TODAY()-3))>100, TODAY()-4,
BLANK())

 

Which works perfectly and does exactly what I want it to do.  However, when I try to use this date, it doesn't work any more:

 

Day Before Last Production Date =
IF(CALCULATE(SUM(YieldDataTable[RunQuantity]), FILTER(YieldDataTable,YieldDataTable[RunDate].[Date]=[Last Production Date]-1))>100, [Last Production Date],
IF(CALCULATE(SUM(YieldDataTable[RunQuantity]), FILTER(YieldDataTable,YieldDataTable[RunDate].[Date]=[Last Production Date]-2))>100, [Last Production Date]-2,
IF(CALCULATE(SUM(YieldDataTable[RunQuantity]), FILTER(YieldDataTable,YieldDataTable[RunDate].[Date]=[Last Production Date]-3))>100, [Last Production Date]-3,
IF(CALCULATE(SUM(YieldDataTable[RunQuantity]), FILTER(YieldDataTable,YieldDataTable[RunDate].[Date]=[Last Production Date]-4))>100, [Last Production Date]-4,
BLANK())

 

Any help is appreciated!

3 REPLIES 3
MFelix
Super User
Super User

Hi @Anonymous ,

 

First of all the use of consecutive if's should be avoided due to the fact that you will get lost in the calculations and it weights on the measures, on your case believe that the problem is with the parenthisis that are not matching.

 

For making this type of calculation you should apply SWITCH (that evaluates an expression against a list of values and returns one of multiple possible result expressions. documentation)

 

Try to use the following rewritten measure:

Day Before Last Production Date =
SWITCH (
    TRUE ();
    CALCULATE (
        SUM ( YieldDataTable[RunQuantity] );
        FILTER ( YieldDataTable; YieldDataTable[RunDate].[Date] = [Last Production Date] - 1 )
    ) > 100; [Last Production Date];
    CALCULATE (
        SUM ( YieldDataTable[RunQuantity] );
        FILTER ( YieldDataTable; YieldDataTable[RunDate].[Date] = [Last Production Date] - 2 )
    ) > 100; [Last Production Date] - 2;
    CALCULATE (
        SUM ( YieldDataTable[RunQuantity] );
        FILTER ( YieldDataTable; YieldDataTable[RunDate].[Date] = [Last Production Date] - 3 )
    ) > 100; [Last Production Date] - 3;
    CALCULATE (
        SUM ( YieldDataTable[RunQuantity] );
        FILTER ( YieldDataTable; YieldDataTable[RunDate].[Date] = [Last Production Date] - 4 )
    ) > 100; [Last Production Date] - 4;
    BLANK ()
)

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Anonymous
Not applicable

Hi, 

Thanks for your reply.  However, I don't believe that was the problem as the measure still does not output anything.  

The output to my last productiond date measure is 10/9/2019, hence the output to this measure should be 10/8/2019.  But it's currently returning blank.

 

I believe it has something to do with how powerbi is comparing dates and how it cannot compare date from a measure to a date in the data table.  However, I don't exactly know why or how to fix it.

 

Do you have any advice?

 

Thanks.

Hi @Anonymous ,

 

Can you share a sample of your file and expected result? If information is sensitive can you do it trough private message?

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.