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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Measure with Static Denominator

I have a data set with volume/value and column with brands and categories in the same column. I need to calculate volume/value share which sales for brand/sales for category. However, when I am putting it against a matrix in front of brand list. I am getting infinity. Please can you help me if there is a workaround.

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

Is this what you want?

percent.PNG

ParentSales = IF(SEARCH("Cat",'Table'[Brand_Cat],,0)<>0,'Table'[Sales])
ParentSales 1 = 
VAR LastNonBlankSales =
    CALCULATE (
        LASTNONBLANK ( 'Table'[ParentSales], 1 ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Index] <= EARLIER ( 'Table'[Index] )
                && NOT ( ISBLANK ( 'Table'[ParentSales] ) )
        )
    )
RETURN
    CALCULATE (
        SUM( 'Table'[Sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Sales] = LastNonBlankSales )
    )
Percent = DIVIDE(MAX('Table'[Sales]),MAX('Table'[ParentSales 1]))

 

Best Regards,

Icey

 

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

8 REPLIES 8
Icey
Community Support
Community Support

Hi @Anonymous ,

Please give me some sample data.

 

Best Regards,

Icey

Anonymous
Not applicable

Sample: Two Columns Brand/Cat and Sales

Brand_Cat            Sales

Drinks (cat)          100

Coca-Cola            50

Pepsi                    50

 

I want to calculate brand share for coca-cola as 50/100. But the problem is when I make a matrix of brand_cat vs brand share. I am getting infinity error. Because as I understand in the row for coca-cola, the denominator becomes 0.

 

Can you help with a workaround please.

 

Icey
Community Support
Community Support

Hi @Anonymous ,

Try this:

1. Add Index column in Power Query Editor.

2. Create columns.

ParentBrand = IF(SEARCH("cat",'Table'[Brand_Cat],,0)<>0,'Table'[Brand_Cat])
ParentBrand 1 =
VAR LastNonBlankBrand =
    CALCULATE (
        LASTNONBLANK ( 'Table'[ParentBrand], 1 ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Index] <= EARLIER ( 'Table'[Index] )
                && NOT ( ISBLANK ( 'Table'[ParentBrand] ) )
        )
    )
RETURN
    IF (
        NOT ( ISBLANK ( 'Table'[ParentBrand] ) ),
        BLANK (),
        CALCULATE (
            MAX ( 'Table'[Brand_Cat] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Brand_Cat] = LastNonBlankBrand )
        )
    )
ParentSales = IF ( SEARCH ( "cat", 'Table'[Brand_Cat],, 0 ) <> 0, 'Table'[Sales] )
ParentSales 1 =
VAR LastNonBlankSales =
    CALCULATE (
        LASTNONBLANK ( 'Table'[ParentSales], 1 ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Index] <= EARLIER ( 'Table'[Index] )
                && NOT ( ISBLANK ( 'Table'[ParentSales] ) )
        )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[Sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Sales] = LastNonBlankSales )
    )

 3. Create Percent Measure.

Percent Measure = DIVIDE(SUM('Table'[Sales]),MAX('Table'[ParentSales 1]))

brand2.PNG

PBIX file attached.

 

Best Regards,

Icey

 

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

Anonymous
Not applicable

Hi This is really helpful. But can you really help if I have data across time periods too suppose the same data is for 4 different time periods.

 

or for example in excel: I can look for time period and category combination and populate it for brands.

Icey
Community Support
Community Support

Hi @Anonymous ,

Please give me a table with a complete data structure, I will conduct a specific test. You can use DropBox, GoogleDrive, OneDrive, etc. Attach the link.

 

Best Regards,

Icey

 

Anonymous
Not applicable

Hi,

 

My data structure is this:

TimePeriodBrand_CatSales
This MonthCat100
This MonthPepsi50
This MonthCoca-Cola50
Last MonthCat200
Last MonthPepsi150
Last MonthCoca-Cola50
Past 3 MonthsCat3000
Past 3 MonthsPepsi1000
Past 3 MonthsCoca-Cola2000

 

Sorry I can't access any cloud service from my network.

Icey
Community Support
Community Support

Hi @Anonymous ,

Is this what you want?

percent.PNG

ParentSales = IF(SEARCH("Cat",'Table'[Brand_Cat],,0)<>0,'Table'[Sales])
ParentSales 1 = 
VAR LastNonBlankSales =
    CALCULATE (
        LASTNONBLANK ( 'Table'[ParentSales], 1 ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Index] <= EARLIER ( 'Table'[Index] )
                && NOT ( ISBLANK ( 'Table'[ParentSales] ) )
        )
    )
RETURN
    CALCULATE (
        SUM( 'Table'[Sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Sales] = LastNonBlankSales )
    )
Percent = DIVIDE(MAX('Table'[Sales]),MAX('Table'[ParentSales 1]))

 

Best Regards,

Icey

 

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

Anonymous
Not applicable

Absolutely, this is what I needed! Thanks a lot!

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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