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
joetech
Helper I
Helper I

Max Date of a previous month based on condition

Hello!

I've got a table with a series of months and values, like this:

CustomerAgreement start dateTypeDateCalculated column I want: latest start date where type = new acquisition and customer = same
12341/6/2020New Aquisition1/1/2021

1/6/2020

 

1234 Renewal1/1/20221/6/2020
12341/6/2022New Acquistion1/1/20231/6/2022
12341/6/2022Renewal1/1/20231/6/2022
44142/7/2022New Acquisition1/1/20232/7/2022

 

It needs a calculated column because I'm trying to make it a matrix, where the rows are the start dates and the columns are the dates. 

 

I've tried this, but get a circular dependency:

Last Date =
VAR Current_Date = 'table'[Agreement Start Date]
VAR Current_Name = 'table'[customer]
RETURN
CALCULATE( MAX('table'[agreement start date]),
'table'[Agreement Start Date] < Current_Date,
'table'[customer] = Current_Name, 'table'[type] = "New Acquisition")
 
Do I need to make a new date table for this to work?
1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @joetech 

Try this, create the column

Test = 
var _latest=CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[Customer]=EARLIER('Table'[Customer]) && 'Table'[Date] <= EARLIER('Table'[Date]) && 'Table'[Type] = "New Acquisition"))
return  CALCULATE(MAX('Table'[Agreement startate ]),FILTER(ALL('Table'),'Table'[Customer]=EARLIER('Table'[Customer]) &&'Table'[Date]=_latest && 'Table'[Type] = "New Acquisition"))

result

vxiaotang_0-1639390767571.png

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-xiaotang
Community Support
Community Support

Hi @joetech 

Try this, create the column

Test = 
var _latest=CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[Customer]=EARLIER('Table'[Customer]) && 'Table'[Date] <= EARLIER('Table'[Date]) && 'Table'[Type] = "New Acquisition"))
return  CALCULATE(MAX('Table'[Agreement startate ]),FILTER(ALL('Table'),'Table'[Customer]=EARLIER('Table'[Customer]) &&'Table'[Date]=_latest && 'Table'[Type] = "New Acquisition"))

result

vxiaotang_0-1639390767571.png

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Perfect. great job.

VahidDM
Super User
Super User

Hi @joetech 

 

Try this:

Column =
VAR _A =
    FILTER (
        ALL ( 'table' ),
        'table'[Customer] = EARLIER ( 'table'[Customer] )
            && 'table'[Type] = "New Aquisition"
    )
RETURN
    MAXX ( _A, [Agreement start date] )

 

Output:

VahidDM_0-1639024790397.png

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Hi,

In this case, the first two rows are reporting the wrong dates, as the start date for the first row in your custom column is later than the agreement start date of that row. 

Hi @joetech 

 

You said, you want: latest start date where type = new acquisition and customer = same


four first rows in the table have the same customer number! so please check your post and update that with new description

 


Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

smpa01
Super User
Super User

@joetech  you can utilize this either as a measure or calculated column

Column = 
VAR _mxCustomer = calculate(MAX(tbl[Customer]))
VAR _mxDate = CALCULATE(MAX(tbl[Agreement start date]),FILTER(ALL(tbl),tbl[Customer]=_mxCustomer&&tbl[Type]="New Acquisition"))
RETURN _mxDate

 

pbix is attached

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi,

In this case, the first two rows are reporting the wrong dates, as the start date for the first row in your custom column is later than the agreement start date of that row. 

 

if a customer has 2 "New Acquisitions" types, they'll have 2 different start dates. 

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