Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

How to compare values for two specific dates

I want to compare values between last date and second last date. The date table has future dates as well so I am filtering the date with the non null FactCovidADCDaily[Daily Census (Total)] value. Here is my DAX:

 

Second Last Date =
CALCULATE (
MAX ( DimDate[Date] ),
FILTER ( DimDate, 'DimDate'[Date] <> MAX ( DimDate[Date] )),
FILTER(FactCovidADCDaily, FactCovidADCDaily[Daily Census (Total)] <> BLANK() ))
 
Last Date =
CALCULATE (
MAX ( DimDate[Date] ),
FILTER(FactCovidADCDaily, FactCovidADCDaily[Daily Census (Total)] <> BLANK() ))
 
Problem 1 : I don't know why but both "Last Date" and "Second Last Date" is displaying the same result. Am I doing anything wrong?
 
Problem 2 : Can you please provide me a DAX for -
                    If FactCovidADCDaily[Daily Census (Total)] on Second Last Date > Last Date then 1 else 0

1 Reply

  • Hi Anonymous ,

     

    On the second last date you are picking up all the dates except the max date however since you are getting the full values of the table you always get the same values.

     

    I don't know how you have your information but  the second last date can be picked up with something similar to:

    Second Last Date = 
    MAXX (
        FILTER (
            ALLSELECTED(FactCovidADCDaily);
            FactCovidADCDaily[Daily Census (Total)] <> BLANK ()
                && FactCovidADCDAily[Date] < MAX ( DimDate[Date] )
        );FactCovidADCDaily[Date]
    
    )