Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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!
Hi @ningty09 ,
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
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsHi,
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 @ningty09 ,
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
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsCovering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
94 | |
82 | |
66 | |
58 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |