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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Logesshwar
New Member

DAX Measure to Divide row value by filtered row value from same table

I have 2 Tables Sample Data.JPG

Problem:
I need to calculate Fair Share Index (share of product in a region/ share of its cat in the same region), which is essentially division of ratios. The first part will have the Product Sales(Dollar Sales) in a Geography for a Time Period divided by Product Sales at National level from Table 1. The second part will have the Category Sales (Cat Dollar Sales) in the same Geography for same Time Period divided by Category Sales at the National Level from Table 2

 

I need a new Measure in Table 1 with this formula:
For each row: Index = [ (Table 1 row[Dollar Sales] / Table 1 [Dollar Sales] where [Geography] == "National" & [Time] == row[Time] & [Prod] = row[Prod]) / (Table 2 row [Cat Dollar Sales] / Table 2 [Cat Dollar Sales] where Geography == "National") ] * 100

 

Example:
Consider the Bold and Italicized Row in above Table 1. The calculation will be as follows,

Fair Share Index = [ (100/500) / (1000/10000)) ] * 100
= [ (0.2) / (0.1) ] * 100
= 200%

 

What I have Tried:

I have joined the Tables in the Data Model on Product Column with Many to Many cardinality and Table 1 filters Table 2.

I have tried implementing several type of DAX queries but everything throws an error. I'm new to PowerBI especially DAX. I have done the same in Python with no issues. So any pointers on how I can achieve this would be greatly appreciated. Thanks in advance

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi  @Logesshwar 

 

You can create a calculated column in table 1 with below DAX:

Column =
VAR a =
    DIVIDE (
        CALCULATE ( SUM ( 'Table 1'[Dollar Sales] ) ),
        SUMX (
            FILTER (
                ALL ( 'Table 1' ),
                'Table 1'[Product] = EARLIER ( 'Table 1'[Product] )
                    && 'Table 1'[Time] = EARLIER ( 'Table 1'[Time] )
                    && 'Table 1'[Geography] = "National"
            ),
            'Table 1'[Dollar Sales]
        )
    )
VAR b =
    DIVIDE (
        CALCULATE (
            SUM ( 'Table 2'[Cat Dollor Sales] ),
            'Table 2'[Product] = EARLIER ( 'Table 1'[Product] )
                && 'Table 2'[Geography] = EARLIER ( 'Table 1'[Geography] )
                && 'Table 2'[Time] = EARLIER ( 'Table 1'[Time] )
        ),
        CALCULATE (
            SUM ( 'Table 2'[Cat Dollor Sales] ),
            'Table 2'[Product] = EARLIER ( 'Table 1'[Product] )
                && 'Table 2'[Geography] = "National"
                && 'Table 2'[Time] = EARLIER ( 'Table 1'[Time] )
        )
    )
RETURN
    DIVIDE ( a, b )

vjingzhang_0-1682070534633.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi  @Logesshwar 

 

You can create a calculated column in table 1 with below DAX:

Column =
VAR a =
    DIVIDE (
        CALCULATE ( SUM ( 'Table 1'[Dollar Sales] ) ),
        SUMX (
            FILTER (
                ALL ( 'Table 1' ),
                'Table 1'[Product] = EARLIER ( 'Table 1'[Product] )
                    && 'Table 1'[Time] = EARLIER ( 'Table 1'[Time] )
                    && 'Table 1'[Geography] = "National"
            ),
            'Table 1'[Dollar Sales]
        )
    )
VAR b =
    DIVIDE (
        CALCULATE (
            SUM ( 'Table 2'[Cat Dollor Sales] ),
            'Table 2'[Product] = EARLIER ( 'Table 1'[Product] )
                && 'Table 2'[Geography] = EARLIER ( 'Table 1'[Geography] )
                && 'Table 2'[Time] = EARLIER ( 'Table 1'[Time] )
        ),
        CALCULATE (
            SUM ( 'Table 2'[Cat Dollor Sales] ),
            'Table 2'[Product] = EARLIER ( 'Table 1'[Product] )
                && 'Table 2'[Geography] = "National"
                && 'Table 2'[Time] = EARLIER ( 'Table 1'[Time] )
        )
    )
RETURN
    DIVIDE ( a, b )

vjingzhang_0-1682070534633.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.