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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
rsouza023
Regular Visitor

How to replace a field value with a measure in a table visual?

See the example below:

I have a Revenue, Cost and Margin, and I want the Margin % value to come next. As this Margin% value is relative, it cannot be in the dataset, it must actually be a measure.

How can I replace the value when the selected field is equal to Margin%?

Below are two measurements. One doing the Margin calculation, that is, dividing margin by revenue. And on the other trying to use SELECTEDVALUE+SWITCH to replace the value when the MARGIN% field is used. The result didn't work.

 

 

 

MARGEM = 
VAR RECEITA = CALCULATE(SUM(TESTE2[VALOR]), FILTER(VALUES(TESTE2[RUBRICA]), [RUBRICA] = "RECEITA"))
VAR MARGEM = CALCULATE(SUM(TESTE2[VALOR]), FILTER(VALUES(TESTE2[RUBRICA]), [RUBRICA] = "MARGEM"))
RETURN
MARGEM/RECEITA


Medida = 
VAR SEL = SELECTEDVALUE(TESTE2[RUBRICA])
RETURN
SWITCH(TRUE(), SEL = "MARGEM %", [MARGEM], 0)

 

 

rsouza023_0-1651008130711.png

The expected result would be:

RUBRICAVALOR
RECEITA100
CUSTO-30
MARGEM70
MARGEM %70%


 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @rsouza023 ,

 

Try this:

VALOR Measure =
SWITCH (
    SELECTEDVALUE ( TEST2[RUBRICA] ),
    "MARGEM %",
        VAR RECEITA_ =
            CALCULATE ( SUM ( TEST2[VALOR] ), TEST2[RUBRICA] = "RECEITA" )
        VAR MARGEM_ =
            CALCULATE ( SUM ( TEST2[VALOR] ), TEST2[RUBRICA] = "MARGEM" )
        RETURN
            FORMAT ( DIVIDE ( MARGEM_, RECEITA_ ), "##.00#%" ),
    SUM ( TEST2[VALOR] )
)

Icey_0-1651216352246.png

 

 

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

3 REPLIES 3
Icey
Community Support
Community Support

Hi @rsouza023 ,

 

Try this:

VALOR Measure =
SWITCH (
    SELECTEDVALUE ( TEST2[RUBRICA] ),
    "MARGEM %",
        VAR RECEITA_ =
            CALCULATE ( SUM ( TEST2[VALOR] ), TEST2[RUBRICA] = "RECEITA" )
        VAR MARGEM_ =
            CALCULATE ( SUM ( TEST2[VALOR] ), TEST2[RUBRICA] = "MARGEM" )
        RETURN
            FORMAT ( DIVIDE ( MARGEM_, RECEITA_ ), "##.00#%" ),
    SUM ( TEST2[VALOR] )
)

Icey_0-1651216352246.png

 

 

Best Regards,

Icey

 

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

amitchandak
Super User
Super User

@rsouza023 , Revenue, Cost and Margin are measures then you can also have measure Margin % and show all of them in matrix and use show on Row

 

If these are row values and Margin % is a measure then check for Hybrid display

 

if you are looking for a Hybrid display with Matrix Column and measure
https://community.powerbi.com/t5/Community-Blog/Creating-a-custom-or-hybrid-matrix-in-PowerBI/ba-p/1...
https://community.powerbi.com/t5/Quick-Measures-Gallery/The-New-Hotness-Custom-Matrix-Hierarchy/m-p/...

vote for Hybrid Table
https://ideas.powerbi.com/ideas/idea/?ideaid=9bc32b23-1eb1-4e74-8b34-349887b37ebc

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

@amitchandak 

Thanks for the answer.
In my case it is in fact a hybrid table.
The focus is to build a balance sheet, so the Margin measurements would come right after the nominal margin value.

I'm going to vote for the hybrid solution and try to replicate the solution you shared as a stopgap.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.