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

Return True depending on Date Frequency of Groups

Hey,

 

So I'm trying to figure out how to create the third column 'Infrequent' as seen in the table below. What I need this column to return is whether or not the same ID has had multiple records but 6+ months apart. If the records are 6+ months apart, the Infrequent column would return 1, otherwise 0. However, as you can see with ID #3 in the below table, one record is actually 6+months apart from the other rows, however this also would be 0 as the other two records are not 6months apart. I only want to identify ID's that have never had two records within 6 months of each other.

 

Any help would be much appreciated.

 

Table1:

IDDateInfrequent
101/01/20190
103/02/20190
216/01/20181
220/10/20181
317/03/20180
302/06/20180
331/03/20190
405/06/20171
401/03/20191

 

2 REPLIES 2
AlB
Super User
Super User

Hi @Dominok123 

Try this for your new calculated column, where Table1 is the table you show:

NewColumn =
VAR _AuxTable =
    ADDCOLUMNS (
        CALCULATETABLE ( DISTINCT ( Table1[Date] ); ALLEXCEPT ( Table1; Table1[ID] ) );
        "_Dif";
        VAR _PreviousDate =
            CALCULATE ( MAX ( Table1[Date] ); Table1[Date] < EARLIER ( Table1[Date] ) )
        RETURN
            IF (
                NOT ISBLANK ( _PreviousDate )
                    && DATEDIFF ( _PreviousDate; [Date]; MONTH ) <= 6;
                1;
                0
            )
    )
RETURN
    IF ( SUMX ( _AuxTable; [_Dif] ) = 0; 1; 0 )

See it at work in the attached file

@AlB Thats a pretty good start, appreciate the effort!

 

Testing it out on my real dataset its picking up ID's which have multiple instances of the same date. So ID #30 with two rows of Date: 30/07/2018 is placed as '1'. It also allocates '1' to every row that only has 1 ID. So if theres only one row with ID #60 then that is placed as '1'.

 

My bad, should have made better dummy data to account for these things.

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.