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

Sub total Not working

Hii Everyone,

 

Can someone please help me to fix this Total.

 

Refer attached PBI file.

 

https://easyupload.io/vk2uer

 

 

kazun909_0-1636460934287.png

 

 

Thank you.

1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, 

According to your description, I can roughly understand your requirement, you are facing the error of subtotal not correct in the matrix, right? I think you can try to create a new measure like this:

Total Man Hours111 =

var _summarize=SUMMARIZE('ProductionLinesTasks',[Order_Number],[IndexKey],"1",[Total Man Hours])

var _sum=SUMX(FILTER(_summarize,[Order_Number]=MAX('ProductionLinesTasks'[Order_Number])),[1])

return

IF(ISINSCOPE('ProductionLinesTasks'[Order_Number])&&NOT(ISINSCOPE(ProductionLinesTasks[IndexKey])),_sum,[Total Man Hours])

 

And you can go to the original matrix to place this measure to check the subtotal, you can find it displays correctly:

vrobertqmsft_0-1636621922831.png

 

You can download my test pbix file below

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

5 REPLIES 5
v-robertq-msft
Community Support
Community Support

Hi, 

According to your description, I can roughly understand your requirement, you are facing the error of subtotal not correct in the matrix, right? I think you can try to create a new measure like this:

Total Man Hours111 =

var _summarize=SUMMARIZE('ProductionLinesTasks',[Order_Number],[IndexKey],"1",[Total Man Hours])

var _sum=SUMX(FILTER(_summarize,[Order_Number]=MAX('ProductionLinesTasks'[Order_Number])),[1])

return

IF(ISINSCOPE('ProductionLinesTasks'[Order_Number])&&NOT(ISINSCOPE(ProductionLinesTasks[IndexKey])),_sum,[Total Man Hours])

 

And you can go to the original matrix to place this measure to check the subtotal, you can find it displays correctly:

vrobertqmsft_0-1636621922831.png

 

You can download my test pbix file below

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

Anonymous
Not applicable

Anonymous
Not applicable

Thank you. @Greg_Deckler  But My measure is very complicated.

Total Man Hours =
VAR __selordernumber =
    MAX ( ProductionLinesTasks[Order_Number] )
VAR __selindexkey =
    MAX ( ProductionLinesTasks[Indexkey] )
VAR __previousindex =
    MAX ( ProductionLinesTasks[Index] ) - 1
VAR __nextindex =
    MAX ( ProductionLinesTasks[Index] ) + 1
VAR __previousindexkey =
    CALCULATE (
        MAX ( ProductionLinesTasks[Indexkey] ),
        FILTER (
            ALL ( ProductionLinesTasks ),
            ProductionLinesTasks[Index] = __previousindex
        )
    )
VAR __nextindexkey =
    CALCULATE (
        MAX ( ProductionLinesTasks[Indexkey] ),
        FILTER (
            ALL ( ProductionLinesTasks ),
            ProductionLinesTasks[Index] = __nextindex
        )
    )
VAR __selteam =
    MAX ( ProductionLinesTasks[Team_Name] )
VAR __nextstart =
    CALCULATE (
        MIN ( ProductionLinesTasks[Trans_DateTime] ),
        FILTER (
            ALL ( ProductionLinesTasks ),
            ProductionLinesTasks[Action] = "Start"
                && ProductionLinesTasks[IndexKey] = __nextindexkey
        )
    )
VAR __previouscomplete =
    CALCULATE (
        MAX ( ProductionLinesTasks[Trans_DateTime] ),
        FILTER (
            ALL ( ProductionLinesTasks ),
            ProductionLinesTasks[Action] = "Complete"
                && ProductionLinesTasks[IndexKey] = __previousindexkey
        )
    )
VAR __minstarttime =
    IF (
        ISBLANK (
            CALCULATE (
                MIN ( ProductionLinesTasks[Trans_DateTime] ),
                FILTER (
                    ALL ( ProductionLinesTasks ),
                    ProductionLinesTasks[Action] = "Start"
                        && ProductionLinesTasks[IndexKey] = __selindexkey
                )
            )
        )
            = TRUE (),
        __previouscomplete,
        CALCULATE (
            MIN ( ProductionLinesTasks[Trans_DateTime] ),
            FILTER (
                ALL ( ProductionLinesTasks ),
                ProductionLinesTasks[Action] = "Start"
                    && ProductionLinesTasks[IndexKey] = __selindexkey
            )
        )
    )
VAR __maxendtime =
    IF (
        ISBLANK (
            CALCULATE (
                MAX ( ProductionLinesTasks[Trans_DateTime] ),
                FILTER (
                    ALL ( ProductionLinesTasks ),
                    ProductionLinesTasks[Action] = "Complete"
                        && ProductionLinesTasks[IndexKey] = __selindexkey
                )
            )
        )
            = TRUE (),
        __nextstart,
        CALCULATE (
            MAX ( ProductionLinesTasks[Trans_DateTime] ),
            FILTER (
                ALL ( ProductionLinesTasks ),
                ProductionLinesTasks[Action] = "Complete"
                    && ProductionLinesTasks[IndexKey] = __selindexkey
            )
        )
    )
VAR __summarydata =
    COUNTROWS (
        FILTER (
            Teams_Operators,
            Teams_Operators[Team_Name] = __selteam
                && Teams_Operators[Join_DateTime] <= __minstarttime
                && Teams_Operators[Leave_DateTime] >= __maxendtime
        )
    )
RETURN
    IF (
        __summarydata > 0,
        SUMX (
            SUMMARIZE (
                ProductionLinesTasks,
                ProductionLinesTasks[Indexkey],
                "Total", DATEDIFF ( __minstarttime, __maxendtime, MINUTE )
            ),
            [Total]
        ) * __summarydata,
        BLANK ()
    )

 Hard to figure out from where exactly the error comes. 

@Anonymous Doesn't matter how complicated the measure is as long as it returns the correct value at the row level. Then it is just a matter of summarizing it correctly in a table variable and doing the correct aggregation across it.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@Anonymous This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.

Top Solution Authors