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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Mal_Sondh
Helper II
Helper II

Calculating a Ratio

Hi All,

 

I have data from a single table that looks something like the attached and i need to create a ratio for items 1 and 2, where the calculation is entry id 2/ entry id 1.

The unique keys are Entry ID, Home Id and Period.

 Ratio CalculationRatio Calculation

I was thinking on creating a summary table with filters, but am i little lost.

 

Any ideas on how this can be done?

 

Any help would be appreciated.

 

Thanks

 

 

 
 
1 ACCEPTED SOLUTION

Hi, @Mal_Sondh 

 

You may create a calculated table and modify the measure as below.

 

Calculated table:
Table 2 = DISTINCT('Table'[Entry ID])

Measure:
Result = 
var _entryid = SELECTEDVALUE('Table'[Entry ID])
var _homeid = SELECTEDVALUE('Table'[HomeId])
var _period = SELECTEDVALUE('Table'[Period])
var _value = SELECTEDVALUE('Table'[Value])
return
IF(
    _entryid in FILTERS('Table 2'[Entry ID]),
    DIVIDE(
        _value,
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
                ALLSELECTED('Table'),
                'Table'[Entry ID] = _entryid+1&&
                'Table'[HomeId] = _homeid&&
                'Table'[Period] = _period
            )
        )
    )
)

 

 

Then you need to use entry_id from Table2 as a slicer. Here are the results.

a1.png

a2.png

 

Best Regards

Allan

 

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

5 REPLIES 5
v-alq-msft
Community Support
Community Support

Hi,  @Mal_Sondh 

 

Based on your description, you may create a measure as below.

 

Result = 
var _entryid = SELECTEDVALUE('Table'[Entry ID])
var _homeid = SELECTEDVALUE('Table'[HomeId])
var _period = SELECTEDVALUE('Table'[Period])
var _value = SELECTEDVALUE('Table'[Value])
return
DIVIDE(
    _value,
    CALCULATE(
        SUM('Table'[Value]),
        FILTER(
            ALLSELECTED('Table'),
            'Table'[Entry ID] = _entryid+1&&
            'Table'[HomeId] = _homeid&&
            'Table'[Period] = _period
        )
    )
)

 

 

Result:

e1.png

 

If I misunderstand your thoughts, please show me your expected result. Do mask sensitive data before uploading.

 

Best Regards

Allan

 

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

Thanks everyone - @v-alq-msft i tried your method and it worked - however if i wanted to set the parameters to say just only ever calculate items 1 and 2 - where do i set this parameter?

 

I understand the following code --> When the entry id is 1, use entry id 2, however if i only want the parameters to be 1 and 2, how could i change the code to implement that?

"Table'[Entry ID] = _entryid+1&&"

 

Otherwise your code works and brings back the desired outcome.

 

Hi, @Mal_Sondh 

 

You may create a calculated table and modify the measure as below.

 

Calculated table:
Table 2 = DISTINCT('Table'[Entry ID])

Measure:
Result = 
var _entryid = SELECTEDVALUE('Table'[Entry ID])
var _homeid = SELECTEDVALUE('Table'[HomeId])
var _period = SELECTEDVALUE('Table'[Period])
var _value = SELECTEDVALUE('Table'[Value])
return
IF(
    _entryid in FILTERS('Table 2'[Entry ID]),
    DIVIDE(
        _value,
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
                ALLSELECTED('Table'),
                'Table'[Entry ID] = _entryid+1&&
                'Table'[HomeId] = _homeid&&
                'Table'[Period] = _period
            )
        )
    )
)

 

 

Then you need to use entry_id from Table2 as a slicer. Here are the results.

a1.png

a2.png

 

Best Regards

Allan

 

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

Thanks!

amitchandak
Super User
Super User

@Mal_Sondh 

Not very clear , but try like

M1= calculate(sum(table[value]),table[Entity Id] ="1")
M2 =calculate(sum(table[value]),table[Entity Id] ="2")

M3= calculate(sum(table[value]),allexcept(table,table[Entity Id]))

M4 = divide([M1],[M2])
M5 = divide([M3],[M2])

 

Also refer https://community.powerbi.com/t5/Desktop/Percentage-of-subtotal/td-p/95390

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.

Top Solution Authors