Forum Discussion

Applicable88's avatar
Applicable88
Icon for Impactful Individual rankImpactful Individual
5 years ago
Solved

Measure to sum beyond row context with condition

Hello, summing values in the same row comes more natural, but now I have a problem where the values are always placed irregulary. For instance that is my sample table: Product ProcessNo Time1...
  • PaulDBrown's avatar
    5 years ago

    You should unpivot the Time columns in Power Query (name the Time references  column "TimeRef" and the Value colum "Time")

    Then create the following measures:

     

    Measure1 =
    CALCULATE (
        SUM ( 'Table'[Time] ),
        'Table'[ProcessNo] IN { 1, 4 },
        'Table'[TimeRef] IN { "Time2", "Time3" }
    )
    
    Measure2 =
    VAR C1 =
        CALCULATE (
            SUM ( 'Table'[Time] ),
            FILTER ( 'Table', 'Table'[ProcessNo] = 4 && 'Table'[TimeRef] = "Time2" )
        )
    VAR C2 =
        CALCULATE (
            SUM ( 'Table'[Time] ),
            FILTER ( 'Table', 'Table'[ProcessNo] IN { 1, 4 } && 'Table'[TimeRef] = "Time3" )
        )
    RETURN
        C1 + C2
    

     

    To get:

    I've attached a sample PBIX 

  • Anonymous's avatar
    Anonymous
    5 years ago

    Applicable88 

    Thank you for sharing the sample pbix. In your scenario, you could just create 2 calculated columns in Table2 using Related() to get the expected sum time. 

     

    SumPrepTime = RELATED(Table1[PrepTime])
    SumProdtime = RELATED(Table1[ProdTime])

     

    Paul Zheng _ Community Support Team
    If this post helps, please Accept it as the solution to help the other members find it more quickly.