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
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
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.