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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
SS_1122
Frequent Visitor

Check Date From today to last 30 days

Hey All, 

Thank you in advance for helping me out in this. I have a data where there is a column for continuous dates over last 10 months, I have to create a measure where I need to check whether the last 30 dates from today is present or not , if it is it then "No failures" if it doesn't thenn count the number of dates that are missing.

Kind Regards.

1 ACCEPTED SOLUTION

Hi @SS_1122 ,

 

You can try this measure to achieve your goal. My Sample has data from 2022/10/01 to 2022/12/12, today is 2022/11/14. Last 30 dates is from 2022/11/15 to 2022/12/14. So the measure result should return 2.

Last 30 dates from today is present or not =
VAR _Today =
    TODAY ()
VAR _Last30Days =
    CALENDAR ( _Today + 1, _Today + 30 )
VAR _ADDFlag =
    ADDCOLUMNS (
        _Last30Days,
        "Flag", IF ( [Date] IN VALUES ( 'Table'[Date] ), 1, 0 )
    )
VAR _Count =
    COUNTX ( FILTER ( _ADDFlag, [Flag] = 0 ), [Date] )
RETURN
    IF ( _Count = 0, "No failures", _Count )

Result is as below.

RicoZhou_0-1668417389682.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

4 REPLIES 4
himahady22
New Member

To solve this problem, you can use a DAX formula in Power BI to create a measure that checks if the last 30 dates from today are present in the date column. If all dates are present, it returns "No failures"; if some dates are missing, it counts and returns the number of missing dates. Here’s how you can do it:

Measure = 
VAR Last30Days = 
    FILTER(
        ALL(YourTable),
        YourTable[Date] >= TODAY() - 30 && YourTable[Date] <= TODAY()
    )
VAR MissingDatesCount = 
    30 - COUNTROWS(Last30Days)

RETURN 
    IF(
        MissingDatesCount = 0, 
        "No failures", 
        "Missing " & MissingDatesCount & " dates"
    )

Explanation:

  • Last30Days: This filters the date column to only include the dates within the last 30 days.
  • MissingDatesCount: This calculates how many dates are missing from the last 30 days.
  • RETURN: If all dates are present (i.e., MissingDatesCount equals 0), it returns "No failures." Otherwise, it returns the number of missing dates.

For more solutions and dynamic tools to help you calculate time periods, you can visit our website 30 days from today, where you'll find professional tools to assist in calculating time periods seamlessly.

ToddChitt
Super User
Super User

DAX Measure:

My Count of last 30 days = CALCULATE ( DISTINCTCOUNT('Table'[Dates] ) , 'Table'[Dates] > DATEADD( DAY, -30, TODAY () )

Note this is 'airware', may not be totally accurate.

You may also need a second filter in the CALCULATE function of: 'Table'[Dates] < TODAY()




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





This gives an error saying 'DATEADD' has been used as a tbale filter expression.

I tried something like this :

Last 30 days = CALCULATE ( DISTINCTCOUNT('Sheet1'[Dates] ) , 'Sheet1'[Dates] > DATEADD(Sheet1[Dates], -30,  DAY() )
The data is only this 

Screenshot 2022-11-11 at 16.48.39.png

 

Hi @SS_1122 ,

 

You can try this measure to achieve your goal. My Sample has data from 2022/10/01 to 2022/12/12, today is 2022/11/14. Last 30 dates is from 2022/11/15 to 2022/12/14. So the measure result should return 2.

Last 30 dates from today is present or not =
VAR _Today =
    TODAY ()
VAR _Last30Days =
    CALENDAR ( _Today + 1, _Today + 30 )
VAR _ADDFlag =
    ADDCOLUMNS (
        _Last30Days,
        "Flag", IF ( [Date] IN VALUES ( 'Table'[Date] ), 1, 0 )
    )
VAR _Count =
    COUNTX ( FILTER ( _ADDFlag, [Flag] = 0 ), [Date] )
RETURN
    IF ( _Count = 0, "No failures", _Count )

Result is as below.

RicoZhou_0-1668417389682.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.

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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