Forum Discussion

selpaqm's avatar
selpaqm
Icon for Helper V rankHelper V
6 years ago
Solved

Use EARLIER with if

Hi,

 

i have a table like below.  

IDName1Name2Totalshippedtrue/falseOrdertype
8AX1000300TRUEW
15AX 1200FALSEC
7CX 500TRUEX
16KX 300TRUEW
10CY300100TRUEQ
11DY 200TRUEW
17FY 400TRUEQ

first i need to find weight average for name2 related shipped (as weight)  and total (value which is will be seperated for empty cells.

Total Cost based total = DIVIDE(CALCULATE(SUM(Sheet1[Total]),FILTER(Sheet1,Sheet1[Name2]=EARLIER(Sheet1[Name2])))*Sheet1[shipped],CALCULATE(SUM(Sheet1[shipped]),FILTER(Sheet1,Sheet1[Name2]=EARLIER(Sheet1[Name2]))))
this formula can fix my first part.
however, i need to add if to this formula because if there is an false in true/false column related for name2 i want to ignore the total and all total cost section for same name2 need to be zero.
for above table, Total Cost based total column against X should be zero.
hope everything is clear.
  • You could consider this approach:

     

    Total Cost Based Total =
    VAR adjcosttotal = (your current expression)
    VAR Falserows =
    CALCULATE (
    COUNTROWS ( Sheet1 ),
    ALL(Sheet1), Sheet1[Name]=EARLIER(Sheet1[Name]),
    Sheet1[true/false] = FALSE ()
    )
    RETURN
    IF ( Falserows > 0, 0, adjcosttotal )

2 Replies

  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    You could consider this approach:

     

    Total Cost Based Total =
    VAR adjcosttotal = (your current expression)
    VAR Falserows =
    CALCULATE (
    COUNTROWS ( Sheet1 ),
    ALL(Sheet1), Sheet1[Name]=EARLIER(Sheet1[Name]),
    Sheet1[true/false] = FALSE ()
    )
    RETURN
    IF ( Falserows > 0, 0, adjcosttotal )