Forum Discussion

Msampedro's avatar
Msampedro
Helper I
1 year ago
Solved

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:

 

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):
 

 

  • 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

1 Reply

  • 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