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
Anonymous
Not applicable

Create a Price Recomendation based on the Average Price by Category and Brand for all products

Hi,

I need some help to solve this problem.

I'm trying to create a measure to recomend a price based on the price average for all the products with the same Category and Brand.
My Goal : Matrix Visual with the product's Code, Stock and Price Recomendation.

Sample Data :

Stock = 

CodeStock
AB12320
CD456100
WZ78915
GH98746

 

Product List = 

CodeCategoryBrand
AB123SodaMark
XY321SodaPenn
CD456WaterDoctors
EF654WaterDoctors
WZ789JuicePhoe
GH987JuicePhoe

 

Sales History = 

CodeCategoryBrandPriceDateRetailer
AB123SodaMark121/06/2019ABC
XY321SodaPenn1,521/06/2019ABC
AB123SodaMark1,214/08/2020Gen
CD456WaterDoctors224/03/2020Gen
EF654WaterDoctors1,813/08/2020ABC
EF654WaterDoctors1,710/08/2020Gen
WZ789JuicePhoe304/03/2021Gen
WZ789JuicePhoe2,829/10/2020Gen

 

I was able to solve it by creating a new Table + calculated Column, but not by using a measure.
I would like to solve this with a measure, as it would allow the user to filter the historical data with a Slicer, choosing the period and retailer desired.
But, in my solution the user would have to change the table code.

My solution :

 

Solution Table = 

VAR YearFilter = 2015

return 
FILTER(
    SUMMARIZECOLUMNS(
        'Product List'[Category], 
        'Product List'[Brand], 
        "Average Price", 
        CALCULATE(
            AVERAGE('Sales History'[Price]),
            YEAR('Sales History'[Date]) >= YearFilter
        )
    ), 
    'Product List'[Category]<>BLANK() &&
    'Product List'[Category]<>"N/A"
)
Price Recomendation Column = 

VAR Price =
CALCULATE(
    AVERAGE('Solution Table'[Average Price]),
    FILTER('Solution Table',
    'Solution Table'[Category] = RELATED('Product List'[Category]) && 
    'Solution Table'[Brand] = RELATED('Product List'[Brand])
    )
)

RETURN
Price

 


I added the new column at the Stock table.

I don't know if it's clear enought, but I can give you more information if you need !
My main problem is that when I created a measure the suggested price was zero for the products that are not on my Sales History.

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi @Anonymous 

 

Does it work, Price Recomendation Column, in you pbix file? It does not work will because of the RELATED().If it works will in you pbix, please your pbix after remove privacy information.

I did some change with the dax formula

Price Recomendation Column =
VAR Price =
    CALCULATE(
        AVERAGE( 'Solution Table'[Average Price] ),
        FILTER(
            'Solution Table',
            'Solution Table'[Category] = EARLIER( 'Product List'[Category] )
                && 'Solution Table'[Brand] = EARLIER( 'Product List'[Brand] )
        )
    )
RETURN
    Price

 

As for creating a measure to achieve this result, I have used the following formula, can you try if it works?

price recomendation =
VAR YearFilter =
    SELECTEDVALUE( 'Table'[Date].[Year] )
VAR _Solution_Table =
    FILTER(
        SUMMARIZE(
            ALL( 'Product List' ),
            'Product List'[Category],
            'Product List'[Brand],
            "Average Price",
                CALCULATE(
                    AVERAGE( 'Sales History'[Price] ),
                    YEAR( 'Sales History'[Date] ) >= YearFilter
                )
        ),
        'Product List'[Category] <> BLANK()
            && 'Product List'[Category] <> "N/A"
    )
VAR _1 =
    AVERAGEX(
        FILTER(
            _Solution_Table,
            [Category] = SELECTEDVALUE( 'Product List'[Category] )
                && [Brand] = SELECTEDVALUE( 'Product List'[Brand] )
        ),
        [Average Price]
    )
RETURN
    _1

 

Before this you need to create a Calendar table first used to be a slicer.

I put my pbix file in the attachment you can reference. If some thing wrong please let me know.

 

Best Regards

Community Support Team _ chenwu zhu

 

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

View solution in original post

4 REPLIES 4
v-chenwuz-msft
Community Support
Community Support

Hi @Anonymous 

 

Does it work, Price Recomendation Column, in you pbix file? It does not work will because of the RELATED().If it works will in you pbix, please your pbix after remove privacy information.

I did some change with the dax formula

Price Recomendation Column =
VAR Price =
    CALCULATE(
        AVERAGE( 'Solution Table'[Average Price] ),
        FILTER(
            'Solution Table',
            'Solution Table'[Category] = EARLIER( 'Product List'[Category] )
                && 'Solution Table'[Brand] = EARLIER( 'Product List'[Brand] )
        )
    )
RETURN
    Price

 

As for creating a measure to achieve this result, I have used the following formula, can you try if it works?

price recomendation =
VAR YearFilter =
    SELECTEDVALUE( 'Table'[Date].[Year] )
VAR _Solution_Table =
    FILTER(
        SUMMARIZE(
            ALL( 'Product List' ),
            'Product List'[Category],
            'Product List'[Brand],
            "Average Price",
                CALCULATE(
                    AVERAGE( 'Sales History'[Price] ),
                    YEAR( 'Sales History'[Date] ) >= YearFilter
                )
        ),
        'Product List'[Category] <> BLANK()
            && 'Product List'[Category] <> "N/A"
    )
VAR _1 =
    AVERAGEX(
        FILTER(
            _Solution_Table,
            [Category] = SELECTEDVALUE( 'Product List'[Category] )
                && [Brand] = SELECTEDVALUE( 'Product List'[Brand] )
        ),
        [Average Price]
    )
RETURN
    _1

 

Before this you need to create a Calendar table first used to be a slicer.

I put my pbix file in the attachment you can reference. If some thing wrong please let me know.

 

Best Regards

Community Support Team _ chenwu zhu

 

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

Anonymous
Not applicable

Thank you so much !

 

I'm using this code + I changed one relation from both to single and now it's working perfectly !

Anonymous
Not applicable

Hi @Anonymous 

You should check your relationships I guess

Anonymous
Not applicable

Hi, @Anonymous , thanks for the answer !

The Stock Table is linked with the Product List and the Sales History through the Code column

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.