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
Micha3lS
Helper I
Helper I

Can't fix "Wrong" Total in Matrix

Hello all,

 

I currently have the problem, that I can't get the total to work. I tried to use SUMX to aggregrate and Prodcutgroup level, but still I'm not getting the correct Reulst.

 

The formula looks like this:

 

Target = 
Var _AvgCyclTime = Calculate(                    
                    Divide(SUM(PlanData[Fertigungszeit Verteilzeit]),SUM(PlanData[Vorgangsmenge])),      
                    FILTER(PlanData, PlanData[Produktgruppe] <> "Collabs")
)

RETURN
CALCULATE(
    SUMX(
        VALUES(ProductionLines[Produktgruppe]),
        Divide('scheduled production shifts'[Capacity], _AvgCyclTime)* MIN(PlanData[TargetOEE])
    ),
    KEEPFILTERS(PlanData[Produktgruppe] <> "Collabs")
)

Scheduled production shifts'[capacity'] is another is another measure:

 

Capacity = Sum('scheduled production shifts'[Scheduled Time sec])

 

The Visual looks like this:
Unbenannt.png

 

In the rows it works exactly like intendet, but I can't get the result like shown here: 
https://www.sqlbi.com/articles/obtaining-accurate-totals-in-dax/

I really can't get my head around it and would appreciate an help.
Thank you

Michael

1 ACCEPTED SOLUTION
Micha3lS
Helper I
Helper I

I finally found the Solution.

 

My Calculate was at the wrong spot. Here is the working code:

Target = 
SUMX(
    VALUES(ProductionLines[Produktgruppe]),
    CALCULATE(
        Divide('scheduled production shifts'[Capacity], Divide(SUM(PlanData[Fertigungszeit Verteilzeit]),SUM(PlanData[Vorgangsmenge]))) * MIN(PlanData[TargetOEE]),
        KEEPFILTERS(ProductionLines[Produktgruppe] <> "Collabs")
    )
)

 

However putting parts of the Divide into a variable with the same logic is not working. Can you explain why? Or do I only add the modifiers like Filters etc. in the Return and in the variable I only write the formula itself without the other stuff??

Unbenannt.png

View solution in original post

7 REPLIES 7
Micha3lS
Helper I
Helper I

I finally found the Solution.

 

My Calculate was at the wrong spot. Here is the working code:

Target = 
SUMX(
    VALUES(ProductionLines[Produktgruppe]),
    CALCULATE(
        Divide('scheduled production shifts'[Capacity], Divide(SUM(PlanData[Fertigungszeit Verteilzeit]),SUM(PlanData[Vorgangsmenge]))) * MIN(PlanData[TargetOEE]),
        KEEPFILTERS(ProductionLines[Produktgruppe] <> "Collabs")
    )
)

 

However putting parts of the Divide into a variable with the same logic is not working. Can you explain why? Or do I only add the modifiers like Filters etc. in the Return and in the variable I only write the formula itself without the other stuff??

Unbenannt.png

AlexisOlson
Super User
Super User

One potential issue here is that your MIN is not operating in the row context that you're iterating over. That is, it's taking the min over all the Produktgruppe values in the local filter context rather than performing a context transition and only considering the value in the row context.

 

If this is the only problem, you can correct it by wrapping it with CALCULATE to force a context transition.

Target =
VAR _AvgCyclTime =
    CALCULATE (
        DIVIDE (
            SUM ( PlanData[Fertigungszeit Verteilzeit] ),
            SUM ( PlanData[Vorgangsmenge] )
        ),
        FILTER ( PlanData, PlanData[Produktgruppe] <> "Collabs" )
    )
RETURN
    CALCULATE (
        SUMX (
            VALUES ( ProductionLines[Produktgruppe] ),
            DIVIDE ( 'scheduled production shifts'[Capacity], _AvgCyclTime )
                * CALCULATE ( MIN ( PlanData[TargetOEE] ) )
        ),
        KEEPFILTERS ( PlanData[Produktgruppe] <> "Collabs" )
    )

Thanks for your Input, unfotrunately that didn't change the Total Result.

tamerj1
Super User
Super User

Hi @Micha3lS 

can you please share a screenshot of your data model? 
in the visual, what are slicing by?

Hi @tamerj1,

 

Im slicing by the location and a maschinegroup in addtion to the date and year. 

The location and machinegroup are stored in the same table as the Produktgruppe in the Table Productionlines.

 

Here is a Screenshot of the relevant tables:

 

Micha3lS_0-1645861455281.png

 

Hi @Micha3lS 

you need to wrap DIVIDE inside SUMX with CALCULATE

Hi @tamerj1 ,

 

That didn't work either, unfrotunately. Nothing changed.

 

Micha3lS_0-1645944160594.png

 

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