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
AA2019
Frequent Visitor

Row level calculated measure used in Group by or summarize

Hi, 

I have a table/data-set like below, with country, brand, product type and year used as page filters to set context.

Measure M_Avg.Price is calculated, at row level (using AllSelected), and also at page level (which changes based on context). Index of Page level value of M_Avg.Price vs. Row Level Avg.Price is used to classify each product into Economy or Premium (if row price < page price then economy else premium).  Thus the classification changes with context - i.e. if country is filtered to UK, then page price is defined by UK and rows for UK are assigned a bucket based on above rule. From here ,i'd like to create a visual (stacked bar / column ) chart, to show the Sales Amount % of defined product type that is sold within each bucket (see pic), but am not able to figure out how to get the measure in a groupby / summarize etc.  Any suggestions/help would be much appreciated (I'm quite new to PowerBI)

 

CountryBrandProduct TypeYearProductFactValueM_AvgPriceM_Bucket
UKAP12019A1Sales Amount1005.00Economy
UKAP12019A2Sales Amount2008.00Economy
UKAP12019A3Sales Amount30020.00Premium
UKBP12019B1Sales Amount4509.00Economy
UKBP12019B2Sales Amount1505.00Economy
UKBP12019B3Sales Amount30030.00Premium
USCP22019C1Sales Amount10020.00Premium
USCP22019C2Sales Amount20020.00Premium
USCP22019C3Sales Amount25016.67Premium
USDP22019D1Sales Amount30015.00Premium
USDP22019D2Sales Amount40020.00Premium
USDP22019D3Sales Amount35035.00Premium
UKAP12019A1Sales Volume20  
UKAP12019A2Sales Volume25  
UKAP12019A3Sales Volume15  
UKBP12019B1Sales Volume50  
UKBP12019B2Sales Volume30  
UKBP12019B3Sales Volume10  
USCP22019C1Sales Volume5  
USCP22019C2Sales Volume10  
USCP22019C3Sales Volume15  
USDP22019D1Sales Volume20  
USDP22019D2Sales Volume20  
USDP22019D3Sales Volume10  

 

output.png

 

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

Hi  @AA2019 ,

 

Firstly, I cannot find “page price” in your question. So I guess this value is the total value of “Sales Amount” divided by the total value of “Sales Volume”.

 

Page Price =
IF (
    MAX ( 'Table'[Fact] ) = "Sales Amount",
    DIVIDE (
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Fact] = "Sales Amount" )
        ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Fact] = "Sales Volume" )
        )
    )
)

Then I created measure  M_AvgPrice and calculated column M_Bucket.

M_AvgPrice =
IF (
    MAX ( 'Table'[Fact] ) = "Sales Amount",
    SUM ( 'Table'[Value] )
        / CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Country] = MAX ( 'Table'[Country] )
                    && 'Table'[Product] = MAX ( 'Table'[Product] )
                    && 'Table'[Brand] = MAX ( 'Table'[Brand] )
                    && 'Table'[Year]
                    && MAX ( 'Table'[Year] )
                    && 'Table'[Product Type] = MAX ( 'Table'[Product Type] )
            ),
            'Table'[Fact] = "Sales Volume"
        )
)
M_Bucket =
IF (
    ISBLANK ( [Page Price] ),
    BLANK (),
    IF (
        CALCULATE ( [M_AvgPrice], ALL ( 'Table'[Product Type] ) ) <= 'Table'[Page Price],
        "ECO",
        "PRE"
    )
)

Then a measure called “PercentageByGroup” will be need.

PercentageByGroup =
CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[Fact] = "Sales Amount" )
    / CALCULATE (
        SUM ( 'Table'[Value] ),
        ALLEXCEPT ( 'Table', 'Table'[Product Type] ),
        'Table'[Fact] = "Sales Amount"
    )

At last, you can take these fields to get a stacked column visual.

The Axis is "Product Type".The legend is "M_Bucket".The value is "PercentageByGroup".

 

3-4.PNG

 

3-5.PNG

 

Best Regards,

Eads

 

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

5 REPLIES 5
v-eachen-msft
Community Support
Community Support

Hi  @AA2019 ,

 

Firstly, I cannot find “page price” in your question. So I guess this value is the total value of “Sales Amount” divided by the total value of “Sales Volume”.

 

Page Price =
IF (
    MAX ( 'Table'[Fact] ) = "Sales Amount",
    DIVIDE (
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Fact] = "Sales Amount" )
        ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Fact] = "Sales Volume" )
        )
    )
)

Then I created measure  M_AvgPrice and calculated column M_Bucket.

M_AvgPrice =
IF (
    MAX ( 'Table'[Fact] ) = "Sales Amount",
    SUM ( 'Table'[Value] )
        / CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Country] = MAX ( 'Table'[Country] )
                    && 'Table'[Product] = MAX ( 'Table'[Product] )
                    && 'Table'[Brand] = MAX ( 'Table'[Brand] )
                    && 'Table'[Year]
                    && MAX ( 'Table'[Year] )
                    && 'Table'[Product Type] = MAX ( 'Table'[Product Type] )
            ),
            'Table'[Fact] = "Sales Volume"
        )
)
M_Bucket =
IF (
    ISBLANK ( [Page Price] ),
    BLANK (),
    IF (
        CALCULATE ( [M_AvgPrice], ALL ( 'Table'[Product Type] ) ) <= 'Table'[Page Price],
        "ECO",
        "PRE"
    )
)

Then a measure called “PercentageByGroup” will be need.

PercentageByGroup =
CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[Fact] = "Sales Amount" )
    / CALCULATE (
        SUM ( 'Table'[Value] ),
        ALLEXCEPT ( 'Table', 'Table'[Product Type] ),
        'Table'[Fact] = "Sales Amount"
    )

At last, you can take these fields to get a stacked column visual.

The Axis is "Product Type".The legend is "M_Bucket".The value is "PercentageByGroup".

 

3-4.PNG

 

3-5.PNG

 

Best Regards,

Eads

 

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Thanks - will try this and update status..

Hi @AA2019 ,

Have you tested my solution? If my answer is useful, please accept my reply.Thanks!

Best Regards,

Eads

 

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
CheenuSing
Community Champion
Community Champion

Hi @AA2019 ,

 

Can you upload data, pbix and output expected to Google / One Drive and share the link here

to find a solution.

What filter/slicer you will be using at visual level and page level of the report.

 

Cheers

 

CheenuSing

 

 

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

Hi, 

Thank you for helping.

here's the link : https://drive.google.com/file/d/1Qb4jSvBcXQNNdjuJO4LJT5kRthoSS_ba/view?usp=sharing

 

Fields used as page filter = Product Type, Country , Brand and Year

Visual filters = None.  

Depending on the page filter defined context, the classification of a product can change from premium to economy etc. so this should be recalculated. 

The visual should then sum up the sales value column by each M_bucket and group by Product Type 

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.

Top Solution Authors