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
acamar22
Frequent Visitor

Conditional DatesInBetween() to examine Past data in today's perspective.

Hi all,

 

I'm hoping someone has tips on a problem I've been struggling with for days.

 

For context, here is a graph of Failure Count Based on Production Year:

acamar22_0-1714169557380.png

 

Obviously the more recent Production Months will have less failures as they haven't had enough time to fail.

I want to compare my current 4 month failure count at the same time last year.

 

I'd also like to show this 4 month failure count at all points in time. (similar to rolling average)

This is how the data comes:

 

acamar22_1-1714170727955.png

 

 

For example, If I wanted to look at the specific 4-month failure count in 4/24/2023, for failures during (12/24/2022 - 4/24/2023), I would only count a failure if the Fail Date and Production Date took place during that time.

 

I currently have this measure:

acamar22_3-1714172828574.png

However, this is not cancelling the failures whose production dates fall out of the time frame.

 

I've made other measures, but they always compare the row to itself.

 

Example: Examining May as the Base Date.

acamar22_2-1714172742775.png

 

Please let me know if thats clear, or if any clarification is needed

 

5 REPLIES 5
lbendlin
Super User
Super User

That's a typical "Period Over Period To Date"  pattern. 

 

Obligatory warning! SAMEPERIODLASTYEAR does NOT produce comparable results especially for number of days below 7. Weekdays WILL differ between years.

 

With that out of the way - Combine SAMEPERIODLASTYEAR with a "Is this date before the current date last year?" filter. You can create that filter from a column in your calendar table or via EDATE(-12)

Hi @lbendlin 

Is it possible to do this using DatesinPeriod() ?

I ask because I want this to be a regular bar/line graph showing the 4 month past failures for each point date.

 

That is one option.  Usually there are many different ways in DAX to achieve the same thing. At the end of the day you have to balance code readability and performance.

Thanks for the help @lbendlin 

 

I guess what I need is to find a way to filter my count based on that top date that is currently being looked at. (When I put it in a Matrix)

 

So it is looking back at 30 days of data. I want to relate that maximum/base failure date to each individual production date within those 30 days.

 

When I code it, it seems to relate the individual production date to the individual failure date within each row of those 3 months.

 

Any Idea how to fix this?

 

 

acamar22_0-1714249376974.png

 

LASTDATE likely is not what you need.  Go with MAX([Fail Date]) instead and make it a variable outside of CALCULATE.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

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.

Top Solution Authors