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

How to calculate Max and Second largest date measure

Hi All,

 

 How to calculate Max and Second largest date measure using Created Date column and calculate Total amount where Invoice date less than equal to last date and greater than equal to second largest Date.

 

Raw Data:-

 

 

 

 

Product

Invoice Date

Create Date

Cust Id

amt

Prod1

7/11/2019

7/5/2019

1001

1.2

Prod1

7/10/2019

7/6/2019

1001

0.4

Prod1

7/9/2019

7/7/2019

1001

0.3

Prod2

7/8/2019

7/8/2019

1001

1.5

Prod2

7/10/2019

7/10/2019

1001

2.5

Prod3

7/11/2019

7/13/2019

1001

0.4

Prod1

7/15/2019

7/10/2019

1002

1.2

Prod2

7/8/2019

7/11/2019

1002

0.4

Prod3

7/11/2019

7/12/2019

1002

0.3

Prod3

7/14/2019

7/15/2019

1002

1.5

Prod1

7/10/2019

7/8/2019

1003

2.5

Prod2

7/11/2019

7/10/2019

1003

1.2

Prod3

7/15/2019

7/12/2019

1003

0.4

Prod1

7/10/2019

7/11/2019

1004

0.3

Prod2

7/11/2019

7/12/2019

1004

1.5

Prod3

7/15/2019

7/15/2019

1004

2.5

 

Output:-

 

 

 

 

Product

Pre Date

Last Date

Cust Id

Amt

Prod1

7/10/2019

7/13/2019

1001

1.2

Prod1

7/10/2019

7/13/2019

1001

0.4

Prod1

7/10/2019

7/13/2019

1001

2.5

Prod2

7/10/2019

7/13/2019

1001

0.4

Prod1

7/12/2019

7/15/2019

1002

1.2

Prod3

7/12/2019

7/15/2019

1002

1.5

Prod1

7/10/2019

7/12/2019

1003

2.5

Prod2

7/10/2019

7/12/2019

1003

1.2

Prod3

7/10/2019

7/12/2019

1003

0.4

Prod3

7/12/2019

7/15/2019

1004

2.5

 

Thanks,

Varsri

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous 

 

Try these MEASURES

 

Last_date =
CALCULATE ( MAX ( Table1[Create Date] ), ALLEXCEPT ( Table1, Table1[Cust Id] ) )
Second_Last_Date =
VAR Mydate = [Last_date]
RETURN
    CALCULATE (
        MAX ( Table1[Create Date] ),
        ALLEXCEPT ( Table1, Table1[Cust Id] ),
        Table1[Create Date] < MyDate
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

1 REPLY 1
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous 

 

Try these MEASURES

 

Last_date =
CALCULATE ( MAX ( Table1[Create Date] ), ALLEXCEPT ( Table1, Table1[Cust Id] ) )
Second_Last_Date =
VAR Mydate = [Last_date]
RETURN
    CALCULATE (
        MAX ( Table1[Create Date] ),
        ALLEXCEPT ( Table1, Table1[Cust Id] ),
        Table1[Create Date] < MyDate
    )

Regards
Zubair

Please try my custom visuals

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.