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
Anonymous
Not applicable

How to get the sum of a measure column in a table

I am using the below formula to get the sum of hours from the most current work date (Current Earned-Used Hours +(-))...I see online that there are issues getting the total when using measures.  I want to create a card with the total hours versus using the totals at the end of a table which will have the wrong sum.  How can I write a formula for the card that will give me the proper sum of the Current Earned-Used Hours +(-)?

 

Total of Measure.png

 
Current Earned-Used Hours +(-) =
CALCULATE(
    SUM('ProjectDetails'[Earned - Used Hours + (-)]),
    FILTER(
        ALL(ProjectDetails[Work Date]),
        'ProjectDetails'[Work Date]=MAX('ProjectDetails'[Work Date])
    )
)
1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

You may delete the created measure [Current Earned-Used Hours +(-) TEST VERSION] in your pbix file, then create new measure which will refer to the original measure [Current Earned-Used Hours +(-)] using DAX below.

 

Current Earned-Used Hours +(-)_New =
VAR _table =
    SUMMARIZE (
        'ProjectDetails',
        'ProjectDetails'[Project Number],
        "_Value", [Current Earned-Used Hours +(-)]
    )
RETURN
    IF (
        HASONEVALUE ( 'ProjectDetails'[Project Number] ),
        [Current Earned-Used Hours +(-)],
        SUMX ( _table, [_Value] )
    )
 

75.png

 

 

 

Best Regards,

Amy

 

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

25 REPLIES 25
Anonymous
Not applicable

Amy...I really appreciate all of the effort you put into helping try and figure this out!

danextian
Super User
Super User

Hello @kentyler ,

 

Try this:

Measure =
SUMX (
    SUMMARIZE (
        VALUES ( ProjectDetails[Work Date] ),
        ProjectDetails[Work Date],
        "Hours", [Expression]
    ),
    [Hours]
)

More details can be found here: https://community.powerbi.com/t5/Desktop/Change-subtotal-calculation-of-matrix-from-Average-to-Sum/t...





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.
Anonymous
Not applicable

I do not understand this portion of the formula.  Can you explain?

Thx

"Hours", [Expression]
    ),
    [Hours]
)

 

kentyler
Solution Sage
Solution Sage

 

 

 
 
Current Earned-Used Hours +(-) =
VAR current_work_date = MAX('ProjectDetails'[Work Date]
 VAR unused_hours = CALCULATE(
    SUM('ProjectDetails'[Earned - Used Hours + (-)]),
   FILTER(
        ALL(ProjectDetails[Work Date]),
        'ProjectDetails'[Work Date]= current_work_date)
    )
RETURN unused_hours
)
This may be a case where Slogan 6 from BISlogans.com , "Use a few simple tricks to improve your DAX code: Always use Variables"  can help. You can calculate the current date and store it in a variable before you start your CALCULATE() expression. Inside the expression you can use the variable. That way whatever changes CALCULATE makes to the filter context will not affect which date is selected as the "current_date". It has the added advantage that you can temporarily have the measure RETURN curren_work_date as a way of checking that the correct dates are being used. 




Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Anonymous
Not applicable

Alas this formula returned the same result as the original (-1370 but the actual result should be -11,408)...thoughts?

Earned-Used Hours Screen Shot_New Formula.png

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.