Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
alamp
Frequent Visitor

Previous Cost of a product for the selected date.

Hi All,

I have  a tabel with Product, cost, quantity,filedate,brand. I want to calculate previous date cost based on the filedate column.

My calculation is not giving me correct result for cost. I have calculated current cost which takes minimum of a product on the selected date for the brand. 

 

Below is the table. 

Product    Cost  Qty   filedate        Brand

product1 $101  320  31/10/2023  kellogs

product8 $721  80    31/10/2023  kellogs

product2 $1500 50   29/10/2023  parle

product3 $360  150  28/10/2023  parle

product4 $46    980  26/10/2023  kellogs

Below are my measures.

Measure 1

 

CostMeasureMin =
VAR SelectedDate =
    SELECTEDVALUE ( 'all_disti_og'[filedate] )
VAR TodaysDate =
    TODAY ()
VAR FilteredDate =
    IF ( ISBLANK ( SelectedDate ), TodaysDate, SelectedDate )
VAR CostOnFilteredDate =
    CALCULATE (
        MIN( all_disti_og[cost] ),
        'all_disti_og'[aq_vendor] IN VALUES ( 'all_disti_og'[aq_vendor] )
    )
RETURN
    CostOnFilteredDate




Measure 2

 

y date =
VAR seldate = SELECTEDVALUE(all_disti_og[filedate])

VAR Prevdate = CALCULATE(
                    MAX(all_disti_og[filedate]),
                    FILTER(
                        ALL(all_disti_og),
                        all_disti_og[filedate] < seldate
                    )
)

VAR Result =
CALCULATE(
    MAX(all_disti_og[filedate]),
    FILTER(ALL(all_disti_og),all_disti_og[filedate] = Prevdate)
)

RETURN
Result
----------------------------------------------
Based on measure 2 i want to get previous cost but could not get it. Then i want to get the cost difference from previous and today.
Need your expertise to resolve it. 

 

 

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @alamp ,

Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

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

Hi @Dangar332 ,

 

Thanks for the response. I used the fromula but it is providing total cost for the product. I think i missed one more filter of manufactures. Let me put a small file so that you could guide me better. 

Dangar332
Super User
Super User

Hi, @alamp 

 

as i understood your problem try below

pre date = MAXX(FILTER(ALL(cost),cost[filedate]<MAX(cost[filedate]) && cost[brand]=MAX(cost[brand])),cost[filedate])


result = 
var a = MAXX(FILTER(ALL(cost),cost[filedate]<MAX(cost[filedate]) && cost[brand]=MAX(cost[brand])),cost[filedate])
return 
SUMX(FILTER(ALL(cost),cost[filedate]=a),cost[cost])

 

Dangar332_0-1698866911332.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.