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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Msampedro
Helper I
Helper I

Give decimal format

Hi @Anonymous 

 

Opening a new thread as I am still experencing the format issue: When adding a new attribute/calculation  ("ASP, EUR/lt") I am not able to give decimal format. Below what I have tried:

 

Many thanks 🙂

 

1) Included in the PnL Structure as a new attribute:

Msampedro_1-1749801004078.png

 

2) Included as a PnL value:

VAR QtyLiter =
    CALCULATE(
        SUM('P&L'[Value]),
        'P&L'[Attribute] = "Qty (Liter)"
    )    
RETURN
    SWITCH(
        TRUE(),
        SelectedAttribute = "VM %", DIVIDE(VarContribution, NetSales),
        SelectedAttribute = "GM %", DIVIDE(GrossProfit, NetSales),
        SelectedAttribute = "ASP, EUR/lt", DIVIDE(NetSales, QtyLiter),
        CALCULATE(
            SUM('P&L'[Value]),
            'P&L'[Attribute] = SelectedAttribute
        )
    )      
3) Included as a PnL Value (Formatted):
 
Msampedro_0-1749800875312.png

 

1 ACCEPTED SOLUTION
Nasif_Azam
Super User
Super User

Hey @Msampedro ,

 

You're attempting to display a calculated value for the attribute "ASP, EUR/lt" with two decimal places, but it's not formatting correctly in your Power BI report. You've added the new attribute in your data table, implemented the logic in the measure, and defined a formatting rule, but the final result doesn't show as expected.

Fix and Recommendations

1. Ensure Exact Match for the Attribute

You’ve correctly inserted "ASP, EUR/lt" into your DATATABLE definition. However, even a minor difference like an extra space or invisible character can break the string match. To safeguard against this, use the TRIM() function to clean up the string during comparison:

VAR SelectedAttribute = TRIM(SELECTEDVALUE('PnL Structure'[Attribute]))

2. Check the Calculation Logic

For "ASP, EUR/lt", your calculation logic seems appropriate:

DIVIDE(NetSales, QtyLiter)

Just make sure that QtyLiter is not blank or zero to avoid unexpected results. You could also add a BLANK() fallback if needed.

3. Correct Formatting for Two Decimals

In your formatting section, you're using this:

FORMAT(BaseValue, "0.00")

This is the right way to show two decimal places. However, if Power BI falls into the TRUE fallback case instead, it might display a rounded value without decimals.

 

Make the switch condition more reliable by trimming the selected value and explicitly formatting each case:

PnL Value (Formatted) =
VAR BaseValue = [PnL Value]
VAR SelectedAttribute = TRIM(SELECTEDVALUE('PnL Structure'[Attribute]))
RETURN
    SWITCH(
        TRUE(),
        SelectedAttribute IN {"VM %", "GM %"}, FORMAT(BaseValue, "0.00%"),
        SelectedAttribute = "ASP, EUR/lt", FORMAT(BaseValue, "0.00"),
        TRUE, FORMAT(BaseValue, "#,##0")
    )

4. Debugging Tip

If you're unsure which attribute is actually selected, create a temporary measure to show it in a card:

Check Attribute = SELECTEDVALUE('PnL Structure'[Attribute])

This helps confirm whether "ASP, EUR/lt" is selected correctly or not.

Things to remember

  • Use TRIM() to avoid mismatch issues due to spacing.

  • Validate that the correct attribute is selected by visual inspection.

  • Ensure the fallback in SWITCH doesn’t override your formatting logic.

  • Use the "0.00" format explicitly for values where decimals are important.

 

If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.


Best Regards,
Nasif Azam



Did I answer your question?
If so, mark my post as a solution!
Also consider helping someone else in the forums!

Proud to be a Super User!


LinkedIn

View solution in original post

1 REPLY 1
Nasif_Azam
Super User
Super User

Hey @Msampedro ,

 

You're attempting to display a calculated value for the attribute "ASP, EUR/lt" with two decimal places, but it's not formatting correctly in your Power BI report. You've added the new attribute in your data table, implemented the logic in the measure, and defined a formatting rule, but the final result doesn't show as expected.

Fix and Recommendations

1. Ensure Exact Match for the Attribute

You’ve correctly inserted "ASP, EUR/lt" into your DATATABLE definition. However, even a minor difference like an extra space or invisible character can break the string match. To safeguard against this, use the TRIM() function to clean up the string during comparison:

VAR SelectedAttribute = TRIM(SELECTEDVALUE('PnL Structure'[Attribute]))

2. Check the Calculation Logic

For "ASP, EUR/lt", your calculation logic seems appropriate:

DIVIDE(NetSales, QtyLiter)

Just make sure that QtyLiter is not blank or zero to avoid unexpected results. You could also add a BLANK() fallback if needed.

3. Correct Formatting for Two Decimals

In your formatting section, you're using this:

FORMAT(BaseValue, "0.00")

This is the right way to show two decimal places. However, if Power BI falls into the TRUE fallback case instead, it might display a rounded value without decimals.

 

Make the switch condition more reliable by trimming the selected value and explicitly formatting each case:

PnL Value (Formatted) =
VAR BaseValue = [PnL Value]
VAR SelectedAttribute = TRIM(SELECTEDVALUE('PnL Structure'[Attribute]))
RETURN
    SWITCH(
        TRUE(),
        SelectedAttribute IN {"VM %", "GM %"}, FORMAT(BaseValue, "0.00%"),
        SelectedAttribute = "ASP, EUR/lt", FORMAT(BaseValue, "0.00"),
        TRUE, FORMAT(BaseValue, "#,##0")
    )

4. Debugging Tip

If you're unsure which attribute is actually selected, create a temporary measure to show it in a card:

Check Attribute = SELECTEDVALUE('PnL Structure'[Attribute])

This helps confirm whether "ASP, EUR/lt" is selected correctly or not.

Things to remember

  • Use TRIM() to avoid mismatch issues due to spacing.

  • Validate that the correct attribute is selected by visual inspection.

  • Ensure the fallback in SWITCH doesn’t override your formatting logic.

  • Use the "0.00" format explicitly for values where decimals are important.

 

If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.


Best Regards,
Nasif Azam



Did I answer your question?
If so, mark my post as a solution!
Also consider helping someone else in the forums!

Proud to be a Super User!


LinkedIn

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.