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
Anonymous
Not applicable

Calculating the no. of triplicate values within a 12 week timeframe

Hi there,

 

I am currently investigating a dataset that contains the following columns below.  The table refers to a number of assets that appear in a dataset if they have been found to have failed upon inspection.

 

Asset IDDate of input entry
AK-000102-03-2019
AK-001305-03-2020
AK-032117-03-2020
AK-000117-03-2020
AK-001321-03-2020
AK-001324-04-2020
AK-000130-03-2020

 

I am trying to use DAX to create a new variable/measure that calculates the number of Repeat Failures.  A repeat failure would be defined as:

- The same asset (identified by Asset ID) failing three or more times...

- ...within a12 week period

 

So, looking at the dataset above, Asset AK-0013 incurred one repeat failure as it failed three times within a 12 week period, but Asset AK-0001 has zero repeat failures even if it failed three separate times, because the failures occurred over a period greater than 12 weeks.

 

I've used DAX multiple times before for different measures and have always googled intensively before asking on the Community (depending on the keywords).  However this is the first time I'm stumped and will gladly welcome any help and advice on how to create this measure!  If you have any questions or require further elaboration please do ask.

 

Many thanks,

 

apb_123

 

1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi , @Anonymous 

Try measures as below:

flag =
VAR _totalrows =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALL ( 'Table' ), 'Table'[Asset ID] = MAX ( 'Table'[Asset ID] ) )
    )
VAR _mindate =
    MINX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Asset ID] = MAX ( 'Table'[Asset ID] )
                && 'Table'[Date of entry] < MAX ( 'Table'[Date of entry] )
        ),
        'Table'[Date of entry]
    )
VAR c =
    DATEDIFF ( _mindate, MAX ( 'Table'[Date of entry] ), WEEK )
RETURN
    IF ( _totalrows >= 3 && c < 12, "repeat error", BLANK () )
number of Repeat Failures =
VAR a =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALL ( 'Table' ), 'Table'[Asset ID] = MAX ( 'Table'[Asset ID] ) )
    )
VAR b =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Asset ID] = MAX ( 'Table'[Asset ID] )
                && 'Table'[flag] <> BLANK ()
        )
    )
VAR c =
    IF ( a >= 3 && a - b < 2, 1, 0 )
RETURN
    SUMX (
        FILTER ( ALL ( 'Table' ), 'Table'[Asset ID] = MAX ( 'Table'[Asset ID] ) ),
        c
    )

The result wil show as below:

26.png

 

Best Regards,
Community Support Team _ Eason
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

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi , @Anonymous 

Try measures as below:

flag =
VAR _totalrows =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALL ( 'Table' ), 'Table'[Asset ID] = MAX ( 'Table'[Asset ID] ) )
    )
VAR _mindate =
    MINX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Asset ID] = MAX ( 'Table'[Asset ID] )
                && 'Table'[Date of entry] < MAX ( 'Table'[Date of entry] )
        ),
        'Table'[Date of entry]
    )
VAR c =
    DATEDIFF ( _mindate, MAX ( 'Table'[Date of entry] ), WEEK )
RETURN
    IF ( _totalrows >= 3 && c < 12, "repeat error", BLANK () )
number of Repeat Failures =
VAR a =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALL ( 'Table' ), 'Table'[Asset ID] = MAX ( 'Table'[Asset ID] ) )
    )
VAR b =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Asset ID] = MAX ( 'Table'[Asset ID] )
                && 'Table'[flag] <> BLANK ()
        )
    )
VAR c =
    IF ( a >= 3 && a - b < 2, 1, 0 )
RETURN
    SUMX (
        FILTER ( ALL ( 'Table' ), 'Table'[Asset ID] = MAX ( 'Table'[Asset ID] ) ),
        c
    )

The result wil show as below:

26.png

 

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous ,

With help of date table and week Rank you can get 12 week data like this

Last 12 week Sales = CALCULATE(Count(Table[Asset ID]),FILTER(all('Date'),'Date'[Week Rank]>=min('Date'[Week Rank])-12 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

You can filter on > 3

 

Refer, how to deal with the week

https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123

https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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.