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

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.

Reply
monikamishra
Frequent Visitor

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 1
MFelix
Super User
Super User

Hi @monikamishra ,

 

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]

)

 

 


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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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