Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Complex conditions in a column

Hi!!   I'm trying to add a column in a query, that either returns the value of beginning of the year (Opening Balance), year-to-date value (Changes) or beginning of the year value plus year-to-date...
  • Greg_Deckler's avatar
    6 years ago
    So like this?

    Column (YTD) =
    SWITCH([Code],
    "AAA", VAR __Min = MINX(FILTER('Table',[Code]="AAA"),[Date])
    RETURN LOOKUPVALUE('Table'[Value],'Table'[Code],"AAA",'Table'[Date],__Min),
    "BBB", SUMX(FILTER('Table','Table'[Date]<=EARLIER('Table'[Date]) && [Code]="BBB"),[Value]),
    "CCC", 'Table'[Value],
    BLANK()
    )