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
quickbi
Helper II
Helper II

Filtering Calclulations

Hi all,
I'm doing a table with calculation, and presented with an excel structure template to order this calculations.
The problem come when I do the total row. For example I do Revenues calculations and there is a total revenues raw.


The problem arises when I create the calculation formula. For example, in the total revenues line, I apply a selected value filter indicating that if it is a totals line, it should use the formula that sums the sales. However, it doesn't work.

quickbi_0-1720937132842.png

Revenues Formula:

PL_Revenues = CALCULATE(
    [PL_Amount],
    'PL Ledger'[Type]="Revenues")

Selected Year Actuals Formula that did not work with totals:

Selected Year Actuals = 

VAR Current_Item=
    SELECTEDVALUE('Income statement'[Level1])

RETURN
    SWITCH(
        TRUE(),
        Current_Item="Total Revenues",[PL_Revenues],
        Current_Item="Total COGS",[PL_COGS],
        Current_Item="Total Gross Profit",[PL_Gross Margin],
        CALCULATE(
            [Actuals],
            FILTER(
                'PL Ledger',
                'PL Ledger'[Income statement.Level1] =Current_Item
            )
        )
)

Selected Year Actuals Formula with 1 that works=

Selected Year Actuals with 1 = 

VAR Current_Item=
    SELECTEDVALUE('Income statement'[Level1])

RETURN
    SWITCH(
        TRUE(),
        Current_Item="Total Revenues",1,
        Current_Item="Total COGS",[PL_COGS],
        Current_Item="Total Gross Profit",[PL_Gross Margin],

        CALCULATE(
            [Actuals],
            FILTER(
                'PL Ledger',
                'PL Ledger'[Income statement.Level1] =Current_Item
            )
        )
)



I have verified that the selected value works by substituting the formula with a "1" to see if the problem lies with the selected value, and it shows correctly. I have also checked the formula separately, and it works. But when I put the formula inside the main formula, it doesn't work.

 

 

Thank you very much.

2 REPLIES 2
Samarth_18
Community Champion
Community Champion

Hi @quickbi ,

 

To answer more specifically we need more information like sample data. However based on your description you could try the below code:-

 

Selected Year Actuals = 
VAR Current_Item = SELECTEDVALUE('Income statement'[Level1])

RETURN
    SWITCH(
        TRUE(),
        Current_Item = "Total Revenues", [PL_Revenues], 
        Current_Item = "Total COGS", [PL_COGS],
        Current_Item = "Total Gross Profit", [PL_Gross Margin],
        CALCULATE(
            [Actuals],
            FILTER(
                'PL Ledger',
                'PL Ledger'[Income statement.Level1] = Current_Item
            )
        )
    )

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Ritaf1983
Super User
Super User

Hi @quickbi 

Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

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.