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

Return previous month value based on two ID's

Hi Everyone, this one calculation is driving me nuts. For some context,  every month a new set of records are added where the values can change or remain consistent.


Essentially I just want a calculated column that displays the previous months "value", for the same productID and CustomerID. I need this as a calculated column

My data looks like this

ProductName/IDCustomerIDValueDateIndex
Product 155555A01/04/20221
Product 155555B01/05/202250
Product 155555B01/06/2022100
Product 2555551001/04/20222
Product 255555701/05/202251
Product 1666661001/06/2022101
Product 1666661201/07/2022151




Looking for a result that looks like this:

ProductName/IDCustomerIDValuePM_ValueDateIndex
Product 155555A 01/04/20221
Product 155555BA01/05/202250
Product 155555BB01/06/2022100
Product 25555510 01/04/20222
Product 25555571001/05/202251
Product 16666610 01/06/2022101
Product 166666121001/07/2022151



1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @Isildur__ 

try to add a calculated column like this:

Value_PM2 = 
VAR _table =
FILTER(
    TableName,
    TableName[ProductName/ID]=EARLIER(TableName[ProductName/ID])
        &&TableName[CustomerID]=EARLIER(TableName[CustomerID])
)

VAR _date  = 
MAXX(
    FILTER(
        _table,
        TableName[Date]<EARLIER(TableName[Date])
    ),
    TableName[Date]
)
RETURN
MAXX(
    FILTER(
        _table,
        TableName[Date] = _date 
    ),
    TableName[Value]
)

 

verified and worked like this:

FreemanZ_0-1674740184635.png

View solution in original post

3 REPLIES 3
Isildur__
Frequent Visitor

Thanks so much, worked perfectly!

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new column.

 

Jihwan_Kim_0-1674740655861.png

 

 

PM_Value CC =
VAR _prevmonthend =
    EOMONTH ( Data[Date], -1 )
RETURN
    MAXX (
        FILTER (
            Data,
            Data[ProductName/ID] = EARLIER ( Data[ProductName/ID] )
                && Data[CustomerID] = EARLIER ( Data[CustomerID] )
                && EOMONTH ( Data[Date], 0 ) = _prevmonthend
        ),
        Data[Value]
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


FreemanZ
Super User
Super User

hi @Isildur__ 

try to add a calculated column like this:

Value_PM2 = 
VAR _table =
FILTER(
    TableName,
    TableName[ProductName/ID]=EARLIER(TableName[ProductName/ID])
        &&TableName[CustomerID]=EARLIER(TableName[CustomerID])
)

VAR _date  = 
MAXX(
    FILTER(
        _table,
        TableName[Date]<EARLIER(TableName[Date])
    ),
    TableName[Date]
)
RETURN
MAXX(
    FILTER(
        _table,
        TableName[Date] = _date 
    ),
    TableName[Value]
)

 

verified and worked like this:

FreemanZ_0-1674740184635.png

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