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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Yonatan1984
Helper I
Helper I

Search Part Cost

Hello to everyone!

I'm trying to see the part cost rate of my Factory.

I've an table from the DB that there is all the costs of all parts of the factory.

There are item numbers that appear several times in the table but on different dates and costs.

In excel, my formula will be:

=INDEX(PART_COST_RATE[RATE],MATCH([PART_CODE]&MAX(IF([PART_CODE]=PART_COST_RATE[PART_CODE],PART_COST_RATE[EFFECT_FROM_DATE])),PART_COST_RATE[PART_CODE]&PART_COST_RATE[EFFECT_FROM_DATE],0))

I search for equivalent formula in power BI.

1 ACCEPTED SOLUTION

@Yonatan1984 

 

If the field types of the two tables are synchronized, it does not matter whether text or number.

Try this:

Column = 
VAR a =
    MAXX (
        FILTER (
            PART_COST_RATE,
            [PART_CODE] = EARLIER ( 'Table'[PART_CODE] )
                && [EFECT_FROM_DATE] <= EARLIER ( 'Table'[MANUFACTURE DATE] )
        ),
        [EFECT_FROM_DATE]
    )
RETURN
    MAXX (
        FILTER (
            PART_COST_RATE,
            [EFECT_FROM_DATE] = a
                && [PART_CODE] = EARLIER ( 'Table'[PART_CODE] )
        ),
        [RATE]
    )

Are you sure there are matching results in the two tables?

 

Best Regards,
Community Support Team _ Janey

View solution in original post

18 REPLIES 18
VahidDM
Super User
Super User

Hi @Yonatan1984 

 

Can you post sample data as text and expected output?
Not enough information to go on;

please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
4. Relation between your tables

Appreciate your Kudos!!
LinkedIn:www.linkedin.com/in/vahid-dm/

Hi @VahidDM 

for Exmple, this is The DB for PART_COST_RATE:

RATEEFECT_FROM_DATEPART_CODE
2001/01/2019111
2501/01/2019222
3021/03/2020111
4501/01/2019333
5001/01/2019444
2630/05/2020111
3905/07/2021444
1012/09/2020333
501/01/2019555
1503/08/2021111
5705/09/2021333
1621/03/2020222

 

This is the output that I need to show:

PART_CODEMANUFACTURE DATEQNTY MANUFACTREDRATECOST
11130/01/2019125320          25,060
22202/04/2019140525          35,125
11130/04/2020128630          38,580
33305/07/202083645          37,620
44420/12/201974550          37,250
11119/08/201994120          18,820
44410/01/2020108650          54,300
33324/04/202198310            9,830
55510/12/202011265            5,630
11123/05/2021130526          33,930
33329/10/201989045          40,050
22223/05/2020133216          21,312

@Yonatan1984 

 

I think you missed to share all data tabels! Can you please explain how did you calculate QNTY or MANUFACTURE DATE?

 


Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

 

Hi @VahidDM 

I did not miss nothing.

The manufacture date and the qnty base on the user input in power apps application that I build.

The rate price is the manufacture cost according to the product tree.

The rate change according to the material cost that we get from the supplier.

For exmple:

Before the covid-19, the prices was stable of the materials.

After the covid-19 started the prices are up.

The manufacture date isn't dependent of the change rate, the factory must to manufactre the items.

 

Hi @Yonatan1984 

 

Use this code to add a RATE column to the output table:

Rate Calculated Column =
VAR _A = [PART_CODE]
VAR _B = [MANUFACTURE DATE]
VAR _C =
    CALCULATE (
        MAX ( PART_COST_RATE[EFECT_FROM_DATE] ),
        FILTER (
            ALL ( PART_COST_RATE ),
            PART_COST_RATE[PART_CODE] = _A
                && PART_COST_RATE[EFECT_FROM_DATE] <= _B
        )
    )
RETURN
    CALCULATE (
        MAX ( PART_COST_RATE[RATE] ),
        FILTER (
            ALL ( PART_COST_RATE ),
            PART_COST_RATE[PART_CODE] = _A
                && PART_COST_RATE[EFECT_FROM_DATE] = _C
        )
    )

 

Output:

VahidDM_0-1640063024947.png

 

 

then multiply the New Rate column by QTY to find the COST.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Hi @VahidDM 

Thanks for the code, I tested the solution and it seems that not all rates are return, their is a blank cells for some items even though they have an rate in the rates table.

other item get the right rates.

@Yonatan1984 

 

Can you share a sample of your data with this scenario (Blank cells with rate)?

 


Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

hi @VahidDM 

Manufactre DB:

Yonatan1984_1-1640149096384.png

Rates DB:

Yonatan1984_2-1640149161794.png

 

 

Hi, @Yonatan1984 


There should be no mistakes according to above formula.

Can you show a screenshot of your code? Let's check if you wrote it wrong.

 

Best Regards,
Community Support Team _ Janey

hi @v-janeyg-msft 

 

There is the code:

Rate Calculated Column = 
VAR _A = [PART_CODE]
VAR _B = [NewDate]
VAR _C =
    CALCULATE (
        MAX ( PART_COST_PRC_RATES[EFCT_FROM_DATE] ),
        FILTER (
            ALL ( PART_COST_PRC_RATES ),
            PART_COST_PRC_RATES[PART_CODE] = _A
                && PART_COST_PRC_RATES[EFCT_FROM_DATE] <= _B
        )
    )
RETURN
    CALCULATE (
        MAX ( PART_COST_PRC_RATES[RATE] ),
        FILTER (
            ALL ( PART_COST_PRC_RATES ),
            PART_COST_PRC_RATES[PART_CODE] = _A
                && PART_COST_PRC_RATES[EFCT_FROM_DATE] = _C
        )
    )

 

There is the screen shot:

Yonatan1984_0-1640508265837.png

 

Hi, @Yonatan1984 

 

Any updates? I don't get your reply and don’t know if your problem has been solved.

HI @v-janeyg-msft 

I checked and it dosen't work.

All the format are fine ang the same in all the tables.

Hi, @Yonatan1984  

 

If the data type and the table structure are the same, it is logically impossible to have problems. Did you download my file and compare it with your source file? According to the sample you provided, we can only help you here unless you can provide further details.

 

Best Regards,
Community Support Team _ Janey

Hi @v-janeyg-msft 

I checked, and the format of part_code in the tables is text and the date format is date in short date.

I checked your model, and it seems that the part_code format in your model is whole number.

There's a screenshot:

Yonatan1984_0-1641364251987.pngYonatan1984_1-1641364289343.png

Yonatan1984_2-1641364328343.pngYonatan1984_3-1641364361972.png

Yonatan1984_5-1641364449479.pngYonatan1984_6-1641364484105.png

 

 

@Yonatan1984 

 

If the field types of the two tables are synchronized, it does not matter whether text or number.

Try this:

Column = 
VAR a =
    MAXX (
        FILTER (
            PART_COST_RATE,
            [PART_CODE] = EARLIER ( 'Table'[PART_CODE] )
                && [EFECT_FROM_DATE] <= EARLIER ( 'Table'[MANUFACTURE DATE] )
        ),
        [EFECT_FROM_DATE]
    )
RETURN
    MAXX (
        FILTER (
            PART_COST_RATE,
            [EFECT_FROM_DATE] = a
                && [PART_CODE] = EARLIER ( 'Table'[PART_CODE] )
        ),
        [RATE]
    )

Are you sure there are matching results in the two tables?

 

Best Regards,
Community Support Team _ Janey

Hi @v-janeyg-msft 

Now it's work!

Thanks!!

@Yonatan1984 

 

There is my code in the sample I gave you at the beginning... It's okay now.

 

Best Regards,
Community Support Team _ Janey

Hi, @Yonatan1984 

 

Try to change the datetime format of your date column to date column.

Below is my sample. You can check how it differs from your original file.

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.
 
Best Regards,
Community Support Team _ Janey

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.