Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Calculated column

Hey Everyone. Please l want to find dax that can count the number of cycles of a battery for each component. For each component, a cycle corresponds to a period where the intensity has a cnstant sign...
  • tamerj1's avatar
    4 years ago

    Hi Anonymous 
    Here is a sample file with the solution https://we.tl/t-K6pFsGb1qn
    It includes 2 calculated columns. The first check for change of sign (checks for new cycle) 

    New Cycle = 
    VAR CurrentDate = Data[Date]
    VAR CurrentComponentTable = CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[component] ) )
    VAR T1 = FILTER ( CurrentComponentTable, Data[Date] < CurrentDate )
    VAR CurrentIntensity = Data[intensity]
    VAR PreviousDate = MAXX ( T1 , Data[Date] )
    VAR PreviousIntensity = MAXX ( FILTER ( T1, Data[Date] = PreviousDate ), Data[intensity] )
    RETURN
        IF ( ISBLANK ( PreviousIntensity ) || PreviousIntensity * CurrentIntensity < 0, 1, 0 )

    The 2nd column is the cycle sequential number

    cycle # = 
    VAR CurrentDate = Data[Date]
    VAR CurrentComponentTable = CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[component] ) )
    VAR T1 = FILTER ( CurrentComponentTable, Data[Date] <= CurrentDate )
    RETURN
        SUMX ( T1, [New Cycle] )