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
RogerSteinberg
Post Patron
Post Patron

Previous rank value by customer AND product from last month

Hi,

I need to get the previous value by product and customer from the previous month

My data looks likes the following and I need to create a calculated column or measure  ( previous rank value)

dateproductcustomerrank_valueprevious rank  value
janAX10 
janAY20 
janBW30 
janBZ40 
febAX5010
febAY6020
febBW7030
febBZ8040

 

For the sake of simplicity I only put one value column but Ideally I want to replicate this formula for a bunch of other metrics.

I applied this formula and it work for one value metric column but didn't for the others. The formula is identical 

 

CALCULATE(
    FIRSTNONBLANK('Table'[value_rank],1),
    FILTER(
        'Table',
        'Table'[product]=EARLIER('Table'[product])&&
        'Table'[customer]=EARLIER('Table'[customer]) &&
        'Table'[date]<EARLIER('Table'[date])-1)
        )

 

 

 I tried adding the ALL before 'Table' as the first expression of the Filter function but to no avail.

 

Any ideas what may be causing the issue?

 

1 ACCEPTED SOLUTION
harshnathani
Community Champion
Community Champion

Hi @RogerSteinberg ,

 

You can create a Calculated Column

 

Previous Rank =

Var _previousdate = CALCULATE(MAX('Table'[date]),
FILTER(
'Table',
'Table'[product]=EARLIER('Table'[product])&&
'Table'[customer]=EARLIER('Table'[customer]) &&
'Table'[date] < EARLIER('Table'[date]))
)

RETURN
CALCULATE(MAX('Table'[rank_value]),
FILTER(
'Table',
'Table'[product]=EARLIER('Table'[product])&&
'Table'[customer]=EARLIER('Table'[customer]) &&
'Table'[date] = _previousdate))
 
 
 
 
1.jpg
 
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

View solution in original post

2 REPLIES 2
v-yingjl
Community Support
Community Support

Hi @RogerSteinberg ,

Based on your sample data and your formula, it seems work fine. After I tested in another column by this formula, it is applied normally and got the correct result.

previous value.png

Maybe some reasons that cause it is the Time-intelligence functions firstnoblank(), not certain but try to reduce use Time-intelligence functions because it should be based on a calendar date table and create relationships...

Try to modify like this in your dataset:

Column = 
CALCULATE (
    MAX('Table'[Rank_value]),
    FILTER (
        'Table',
        'Table'[product] = EARLIER ( 'Table'[product] )
            && 'Table'[customer] = EARLIER ( 'Table'[customer] )
            && 'Table'[date]
                < EARLIER ( 'Table'[date] ) - 1
    )
)

If not help, could you please consider sharing a dummy .pbix file for further discussion?

 

Best Regards,
Yingjie Li

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

 

harshnathani
Community Champion
Community Champion

Hi @RogerSteinberg ,

 

You can create a Calculated Column

 

Previous Rank =

Var _previousdate = CALCULATE(MAX('Table'[date]),
FILTER(
'Table',
'Table'[product]=EARLIER('Table'[product])&&
'Table'[customer]=EARLIER('Table'[customer]) &&
'Table'[date] < EARLIER('Table'[date]))
)

RETURN
CALCULATE(MAX('Table'[rank_value]),
FILTER(
'Table',
'Table'[product]=EARLIER('Table'[product])&&
'Table'[customer]=EARLIER('Table'[customer]) &&
'Table'[date] = _previousdate))
 
 
 
 
1.jpg
 
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

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.