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
Syndicate_Admin
Administrator
Administrator

Calculation that takes values prior to the filter date, when the current value is empty

Hello! Need help please! I need to calculate the profitability of a business per month, I have the column sales and quantities sold, and the column cost U. All purchases and sales have month and year and are related to a calendar table.

Not for all items sold in a month I have "cost U" in that same month, some items were purchased in past months. I would need you to use the last cost U for that product in that case. (respecting the current filter, i.e. not the last cost of the entire table, looking for the cost in the months prior to the filtered month)

I made a "last purchase" cost, but I can't get it to work with the visual filter of the page.

When I want to see January sales, I would need to have costs U of January or the last one before that month...

Last Buy Cost =
WHERE _lastDATE= CALCULATE( LASTDATE(Shopping[Date]), filter(Shopping, Shopping[Code]= EARLIER(Shopping[Code])))
return
CALCULATE(Shopping[6-Cost], filter(shopping, Shopping[Code]= EARLIER(Shopping[Code]) && Shopping[Date]= _lastDATE))
Natalia0710_0-1679314791478.jpeg

Thanks a lot!!

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @Natalia0710- ,

Power bi current does not support create dynamic calculate column/table based on filter selections.They work on different levels, and you can't apply the interaction from the child level to affect their parent levels.

For this scenario, I think you need to create measure formula instead.

Notice: the data level of power bi(from parent to child level)

Database(external) -> query table(query, custom function, query parameters) -> data model table(table, calculate column/table) -> data view with virtual tables(measure, visual, filter, slicer)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.