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
pawelj795
Post Prodigy
Post Prodigy

Average for last 30 days if avalaible, otherwise last known value

Hi,

I'm currently calculating the materials average unit price in the last 30 days.
In some cases, formula return blank, because there weren't any purchases for particular items.

For those cases, I want to return the last available value - I mean the last available purchase.

image.pngimage.png

Any idea how to do this?

Thanks in advance 😉

2 ACCEPTED SOLUTIONS

@amitchandak 

I did some adjustments and now it looks like this.

image.png
It seems to be working, but maybe there is something that I've missed.

Please verify, thanks

View solution in original post

@pawelj795 , seem fine. you could have created a couple of measures and just handled then here.

View solution in original post

5 REPLIES 5
v-lionel-msft
Community Support
Community Support

Hi @pawelj795 ,

 

You can refer to the formula.

Measure = 
VAR x = 
CALCULATE(
    AVERAGEX(
        'Table',
        DIVIDE( 'Table'[c1], 'Table'[c2] * 'Table'[c3], BLANK() )
    ),
    DATESINPERIOD( 'Table'[Date], MAX('Table'[Date]), -30, DAY ),
    USERELATIONSHIP( )
)
RETURN
IF( 
    x = BLANK(),
    CALCULATE(),
    x
)

 

Best regards,
Lionel Chen

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

amitchandak
Super User
Super User

@pawelj795 , This can you data of last available date with help from a date table. so when 30-day value is null you can use this

 

Last Day Non Continous = CALCULATE(sum('order'[Qty]),filter(all('Date'),'Date'[Date] =MAXX(FILTER(all('Date'),'Date'[Date]<max('Date'[Date])),Table['Date'])))

Hi @amitchandak 

Thanks for your reply, but could you help me with the implementation of your adjustment?
I tried by myself, but it returns only blanks.

 

image.png

@amitchandak 

I did some adjustments and now it looks like this.

image.png
It seems to be working, but maybe there is something that I've missed.

Please verify, thanks

@pawelj795 , seem fine. you could have created a couple of measures and just handled then here.

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.