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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
jaqcues
Frequent Visitor

Average Sales At Price Point - Dynamic X Axis Using Dax

I am trying to create a chart which displays average dollar sales and # of weeks at certain price levels (increments of 10c) over the last 52 weeks.

Below is an example of how I would like it to look, however this chart is currently incorrect for reasons I will go into below.

 

jaqcues_0-1651781825781.png

The above was made by adding to the fact table (nz_fact_iri) a calculated column for price (dollars/units) rounded up to nearest 1 digit in text format, then using a dimension table with the same values on the x axis, and a basic countrows formula to get the count of weeks at this price. The problem with this method is the chart is only correct at the lowest level, product_description and market_description. If I use any aggregated products (dimension product_fpg) or markets (dimensions banner, account etc) in my slicers and the product_description or market_descriptions from the same group have a different average sale price from each another, the number of weeks per year goes up since the price is static per product - whereas I want the average price to be dynamic depending on whatever products or markets are selected.

As an example if product A's average price/unit was $1.13 and product B's was $1.21 in the same week, selecting A and B in my product filter would result in 2 different weeks on my chart (at <=$1.20 and <=$1.30). I want the price to be averaged within a measure at $1.17, for one week on the chart at <=$1.20).

 

Below I have marked the relational columns - date, market_description and product_aztec_code. Also below are shortened versions of relevant Dim tables and the fact table.

 

jaqcues_1-1651782744604.png 

Dim_Account

market_descriptionBannerRegion
StoreA UNIStoreAUNI
StoreA SIStoreASI
StoreA LNIStoreALNI
StoreB UNIStoreBUNI
StoreB SIStoreBSI
StoreB LNIStoreBLNI

 

Dim IRI_Prod_Attr

product_aztec_codeproduct_descriptionproduct_fpgproduct_categoryproduct_manufacturerproduct_brand
1897767Abcd Vitamin Water Vitamin B Sipper Top 500mlAbcd Vitamin Water 500ml FpgWaterOther MfrsAbcd Vitamin Water Brand
1897769Abcd Vitamin Water Vitamin D Sipper Top 500mlAbcd Vitamin Water 500ml FpgWaterOther MfrsAbcd Vitamin Water Brand
1897768Abcd Vitamin Water Vitamin C Sipper Top 500mlAbcd Vitamin Water 500ml FpgWaterOther MfrsAbcd Vitamin Water Brand
1897766Abcd Vitamin Water Vitamin A Sipper Top 500mlAbcd Vitamin Water 500ml FpgWaterOther MfrsAbcd Vitamin Water Brand

 

nz_fact_iri - contains weekly data

dollarsunitsproduct_aztec_codeproduct_descriptionproduct_frucor_promo_groupmarket_descriptioniri_calendar_date
1469.73551897767Abcd Vitamin Water Vitamin B Sipper Top 500mlAbcd Vitamin Water 500ml FpgStoreA UNI6/03/2022
769.51901897769Abcd Vitamin Water Vitamin D Sipper Top 500mlAbcd Vitamin Water 500ml FpgStoreA SI14/03/2021
2554.75901897768Abcd Vitamin Water Vitamin C Sipper Top 500mlAbcd Vitamin Water 500ml FpgStoreA LNI5/12/2021
106.9211897766Abcd Vitamin Water Vitamin A Sipper Top 500mlAbcd Vitamin Water 500ml FpgStoreB UNI9/05/2021
710.71491897767Abcd Vitamin Water Vitamin B Sipper Top 500mlAbcd Vitamin Water 500ml FpgStoreB SI16/05/2021
1462.54041897769Abcd Vitamin Water Vitamin D Sipper Top 500mlAbcd Vitamin Water 500ml FpgStoreB LNI11/07/2021
866.41901897768Abcd Vitamin Water Vitamin C Sipper Top 500mlAbcd Vitamin Water 500ml FpgStoreA UNI27/06/2021
1221.53481897766Abcd Vitamin Water Vitamin A Sipper Top 500mlAbcd Vitamin Water 500ml FpgStoreA SI28/11/2021
1128.12381897767Abcd Vitamin Water Vitamin B Sipper Top 500mlAbcd Vitamin Water 500ml FpgStoreA LNI23/01/2022
4237.110211897769Abcd Vitamin Water Vitamin D Sipper Top 500mlAbcd Vitamin Water 500ml FpgStoreB UNI27/02/2022
1100.42441897768Abcd Vitamin Water Vitamin C Sipper Top 500mlAbcd Vitamin Water 500ml FpgStoreB SI25/07/2021
12542931897766Abcd Vitamin Water Vitamin A Sipper Top 500mlAbcd Vitamin Water 500ml FpgStoreB LNI27/02/2022

 

I have tried another method which is was sure was a winner - but it is just showing blank values.

I created a calculated table called Histogram Axis using Generateseries with .1 increments, then used this measure:

 

 

 

 

 

Price Count = 
VAR HistogramColumn =
    SELECTEDVALUE ( 'Histogram Axis'[Value] ) 
VAR AvgPriceTable =
    SUMMARIZE (
        nz_fact_iri,
        nz_fact_iri[iri_calendar_date],
        "Price",
       ROUNDUP( [Dollars] / [Units],1)
    )
RETURN
    COUNTROWS (
        FILTER (
            AvgPriceTable,
            [Price] = HistogramColumn  
        )
    ) 

 

 

 

 

 

Any guidance would be much appreciated! This is my first post so please let me know if I have left out any details.

 

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

HI @jaqcues,

According to your description, it seems related to segment requirements. If that is the case, you can take a look at the following link about the dynamic segment if helps:

Dynamic segmentation – DAX Patterns

Regards,

Xiaoxin Sheng

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

View solution in original post

2 REPLIES 2
jaqcues
Frequent Visitor

Thank you so much! This method worked perfectly - exactly what I was looking for.

 

jaqcues_0-1652282661511.png

 

v-shex-msft
Community Support
Community Support

HI @jaqcues,

According to your description, it seems related to segment requirements. If that is the case, you can take a look at the following link about the dynamic segment if helps:

Dynamic segmentation – DAX Patterns

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.