Forum Discussion

cpmb's avatar
cpmb
Frequent Visitor
6 years ago
Solved

Conditional reference to another row in table

Could somebody explain why I am getting the numbers below in the Output column? I had expected to get those in the Desired Output column instead. DAX Formulas are below.

DateGroupIDValueOutputDesired Output
1/1/2019A1555
1/1/2019A2101010
1/1/2019A3151515
1/1/2019B4202020
1/1/2019B5252525
1/2/2019A1-102030
1/2/2019A2303030
1/2/2019B4353535
1/2/2019B5-103535
1/2/2019A3-102030

 

Output = IF(

Table[Value]<0,

CALCULATE([Measure],

FILTER(

SUMMARIZE(Table, Table[Date],Table[Group],Table[ID],Table[Value]),

Table[Date]=EARLIER(Table[Date]) && Table[Group] = EARLIER(Table[Group]) && Table[ID] <> EARLIER(Table[ID])

)), Table[Value])

 

Measure= CALCULATE(

SUM( Table[Value]),

ALLSELECTED(Table[ID]),

FILTER(Table, Table[Date]=Table[Date] && Table[Group]=Table[Group] && Table[ID] = Table[ID]))

 

Any explanation would be great, Thanks.

  •  

    NewCol =
    IF (
        Table1[Value] < 0,
        CALCULATE ( MAX ( Table1[Value] ), ALL ( Table1[ID], Table1[Value] ) ),
        Table1[Value]
    )

     

    Please mark the question solved when done and consider giving kudos if posts are helpful.

    Cheers  Datanaut

5 Replies

  • AlB's avatar
    AlB
    Community Champion

    Hi cpmb 

    Can you explain how the correct numbers are calculated, what the logic is?

     

    Please mark the question solved when done and consider giving kudos if posts are helpful.

    Cheers  Datanaut

     

    • cpmb's avatar
      cpmb
      Frequent Visitor

      The logic is: if Value is negative, take the Value of another ID in the Group (ideally the max).

      • AlB's avatar
        AlB
        Community Champion

         

        NewCol =
        IF (
            Table1[Value] < 0,
            CALCULATE ( MAX ( Table1[Value] ), ALL ( Table1[ID], Table1[Value] ) ),
            Table1[Value]
        )

         

        Please mark the question solved when done and consider giving kudos if posts are helpful.

        Cheers  Datanaut