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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.