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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Formula working but Grand Total not Summing

I have the following formula that is displaying the right numbers but not summing together in the table for the grand total corrrectly.  How can I fix ? Total should be way higher than 18.641m
 
Projected = IF(Calculate( SUMX('6. Actuals','6. Actuals'[Actuals]),'6. Actuals'[Actuals],'Calendar'[Year] = 2022)*-1 = Blank(),Calculate( SUMX('6. Actuals','6. Actuals'[Actuals]),'6. Actuals'[Actuals],'Calendar'[Year] = 2021)*-1,Calculate( SUMX('6. Actuals','6. Actuals'[Actuals]),'6. Actuals'[Actuals],'Calendar'[Year] = 2022)*-1)
 
JMcAnarney_0-1660332995193.png

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following formula.

Projected = 
Var N1=IF (
    CALCULATE (
        SUMX ( '6. Actuals', '6. Actuals'[Actuals] ),
        '6. Actuals'[Actuals],
        'Calendar'[Year] = 2022
    ) * -1
        = BLANK (),
    CALCULATE (
        SUMX ( '6. Actuals', '6. Actuals'[Actuals] ),
        '6. Actuals'[Actuals],
        'Calendar'[Year] = 2021
    ) * -1,
    CALCULATE (
        SUMX ( '6. Actuals', '6. Actuals'[Actuals] ),
        '6. Actuals'[Actuals],
        'Calendar'[Year] = 2022
    ) * -1
)
Return
IF(HASONEVALUE('Calendar'[Month name]),N1,SUMX(VALUES('Calendar'[Month name]),N1))
 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following formula.

Projected = 
Var N1=IF (
    CALCULATE (
        SUMX ( '6. Actuals', '6. Actuals'[Actuals] ),
        '6. Actuals'[Actuals],
        'Calendar'[Year] = 2022
    ) * -1
        = BLANK (),
    CALCULATE (
        SUMX ( '6. Actuals', '6. Actuals'[Actuals] ),
        '6. Actuals'[Actuals],
        'Calendar'[Year] = 2021
    ) * -1,
    CALCULATE (
        SUMX ( '6. Actuals', '6. Actuals'[Actuals] ),
        '6. Actuals'[Actuals],
        'Calendar'[Year] = 2022
    ) * -1
)
Return
IF(HASONEVALUE('Calendar'[Month name]),N1,SUMX(VALUES('Calendar'[Month name]),N1))
 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

tamerj1
Super User
Super User

Hi @Anonymous 

please try

Projected =
SUMX (
    VALUES ( 'Date'[Month Name] ),
    IF (
        CALCULATE (
            SUMX ( '6. Actuals', '6. Actuals'[Actuals] ),
            '6. Actuals'[Actuals],
            'Calendar'[Year] = 2022
        ) * -1
            = BLANK (),
        CALCULATE (
            SUMX ( '6. Actuals', '6. Actuals'[Actuals] ),
            '6. Actuals'[Actuals],
            'Calendar'[Year] = 2021
        ) * -1,
        CALCULATE (
            SUMX ( '6. Actuals', '6. Actuals'[Actuals] ),
            '6. Actuals'[Actuals],
            'Calendar'[Year] = 2022
        ) * -1
    )
)
mahoneypat
Employee
Employee

FYI that You should consider using variables to simplify your code and improve performance (your current measure would do the same query twice is the false path). Here is an example.

 

Projected =
VAR CY =
CALCULATE (
SUMX ( '6. Actuals', '6. Actuals'[Actuals] ),
'6. Actuals'[Actuals],
'Calendar'[Year] = 2022
) * -1
RETURN
IF (
ISBLANK ( CY ),
CALCULATE (
SUMX ( '6. Actuals', '6. Actuals'[Actuals] ),
'6. Actuals'[Actuals],
'Calendar'[Year] = 2021
) * -1,
CY
)

 

Also, to get the expected value in the total row, please follow the approach described in this video.

Power BI - Tales from the front #01 - Getting the Right Total - YouTube

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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