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
jimbob2285
Advocate III
Advocate III

Measure Total not working

Hi

 

I'm hoping someone can help, please.  I have a measure called 'Revenue_SelectedMon_P' in the PBIX file Ledger Transactions  that calculates a value up to a certain user-selected date, but it's not totalling when no projects are selected or more than one project is selected:

 

Revenue_SelectedMon_P = 
--IF(ISFILTERED('ProjectTransactions'[Project]),
    CALCULATE(
        SUM('ProjectTransactions'[Revenue]),
        FILTER(
            ALLSELECTED('ProjectTransactions'),
            'ProjectTransactions'[Project] = SELECTEDVALUE('ProjectTransactions'[Project]) &&
            'ProjectTransactions'[AccountingDate_ME] = SELECTEDVALUE('Month'[AccountingDate_ME])
        )
    )--,
--    SUM('ProjectTransactions'[Revenue])
--)

 

as you can see from the code above, I've tried adding an ISFILTERED condition, but commented it out as that's not working either

 

Can anyone explain what I'm doing wrong please, I'm just getting to grips with Measures and finding them very difficult compared to calculated columns

 

Cheers

Jim

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @jimbob2285 ,

 

The issue with your measure lies in how it handles the filter context for totals and cases where no project or multiple projects are selected. The problem arises because SELECTEDVALUE only works when a single value is selected. If no projects or multiple projects are selected, SELECTEDVALUE returns BLANK, which causes the filter conditions to fail.

To address this, you can modify your measure to account for cases where no specific project is selected or when multiple projects are selected. A better approach is to use ISFILTERED to check if a project filter is applied and adjust the logic accordingly. Here's an updated version of your measure:

Revenue_SelectedMon_P =
IF(
    ISFILTERED('ProjectTransactions'[Project]),
    CALCULATE(
        SUM('ProjectTransactions'[Revenue]),
        FILTER(
            ALLSELECTED('ProjectTransactions'),
            'ProjectTransactions'[Project] = SELECTEDVALUE('ProjectTransactions'[Project]) &&
            'ProjectTransactions'[AccountingDate_ME] = SELECTEDVALUE('Month'[AccountingDate_ME])
        )
    ),
    CALCULATE(
        SUM('ProjectTransactions'[Revenue]),
        FILTER(
            ALLSELECTED('ProjectTransactions'),
            'ProjectTransactions'[AccountingDate_ME] = SELECTEDVALUE('Month'[AccountingDate_ME])
        )
    )
)

This measure works as follows: If a specific project is selected,

the measure calculates the revenue for that project by using SELECTEDVALUE to identify the selected project. It ensures that the filter context includes the selected project and the specific month. If no project or multiple projects are selected, the measure skips the project filter and calculates the total revenue for all projects in the selected month. This way, the measure handles both individual project selections and totals correctly.

The use of ALLSELECTED ensures that slicer and filter contexts applied in the report are respected, while removing row-level filters to properly calculate totals. By structuring the logic with IF(ISFILTERED), the measure explicitly distinguishes between scenarios where a specific project is selected and where no specific selection is made, improving its reliability for both detailed and aggregated views.

If you are still encountering issues, testing intermediate results using a RETURN statement can help identify where the logic needs further adjustment.

 

Best regards,

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @jimbob2285 ,

 

The issue with your measure lies in how it handles the filter context for totals and cases where no project or multiple projects are selected. The problem arises because SELECTEDVALUE only works when a single value is selected. If no projects or multiple projects are selected, SELECTEDVALUE returns BLANK, which causes the filter conditions to fail.

To address this, you can modify your measure to account for cases where no specific project is selected or when multiple projects are selected. A better approach is to use ISFILTERED to check if a project filter is applied and adjust the logic accordingly. Here's an updated version of your measure:

Revenue_SelectedMon_P =
IF(
    ISFILTERED('ProjectTransactions'[Project]),
    CALCULATE(
        SUM('ProjectTransactions'[Revenue]),
        FILTER(
            ALLSELECTED('ProjectTransactions'),
            'ProjectTransactions'[Project] = SELECTEDVALUE('ProjectTransactions'[Project]) &&
            'ProjectTransactions'[AccountingDate_ME] = SELECTEDVALUE('Month'[AccountingDate_ME])
        )
    ),
    CALCULATE(
        SUM('ProjectTransactions'[Revenue]),
        FILTER(
            ALLSELECTED('ProjectTransactions'),
            'ProjectTransactions'[AccountingDate_ME] = SELECTEDVALUE('Month'[AccountingDate_ME])
        )
    )
)

This measure works as follows: If a specific project is selected,

the measure calculates the revenue for that project by using SELECTEDVALUE to identify the selected project. It ensures that the filter context includes the selected project and the specific month. If no project or multiple projects are selected, the measure skips the project filter and calculates the total revenue for all projects in the selected month. This way, the measure handles both individual project selections and totals correctly.

The use of ALLSELECTED ensures that slicer and filter contexts applied in the report are respected, while removing row-level filters to properly calculate totals. By structuring the logic with IF(ISFILTERED), the measure explicitly distinguishes between scenarios where a specific project is selected and where no specific selection is made, improving its reliability for both detailed and aggregated views.

If you are still encountering issues, testing intermediate results using a RETURN statement can help identify where the logic needs further adjustment.

 

Best regards,

danextian
Super User
Super User

Hi @jimbob2285 

The issue lies with this

SELECTEDVALUE('ProjectTransactions'[Project]) 

This will return blank if there are more than one distinct values. At the total level, there is obviously more than one and also why the need to filter the current row by the same current row value? For example you are filtering Highstairs Lane - 28 Plots to Highstairs Lane - 28 Plots which is what this code below does.

'ProjectTransactions'[Project] = SELECTEDVALUE('ProjectTransactions'[Project])

  I would simplify your code as follows:

CALCULATE (
    SUM ( 'ProjectTransactions'[Revenue] ),
    KEEPFILTERS (
        TREATAS (
            VALUES ( 'Month'[AccountingDate_ME] ),
            'ProjectTransactions'[AccountingDate_ME]
        )
    )
)
--TREATAS is used to propagate a filter between non-related tables, IN can be used but generally TREATAS is faster

danextian_0-1733409571608.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.