Forum Discussion
Destrogiro
6 years agoRegular Visitor
EARLIER Function
Hi, I'm new to Power BI and I'm having trouble with EARLIER function. Basically what I need is: ValorTotal = SWITCH(TCBLBI_Peso_Empresas_Tradadas[OrdemGrupo]; 2; EARLIER([Va...
- 6 years ago
Since the introduction of VAR, there's no actual need for EARLIER any longer. So you might want to do it in a different way, perhaps easier to follow conceptually, and forget about EARLIER altogether (which is actually recommended nowadays):
Value2 = SWITCH ( TRUE (), Table1[GroupOrder] IN { 1, 4, 7 }, 0, Table1[GroupOrder] IN { 2, 5, 8 }, VAR PreviousGroupOrder_ = Table1[GroupOrder] - 1 RETURN CALCULATE ( DISTINCT ( Table1[Value 1] ), Table1[GroupOrder] = PreviousGroupOrder_, ALLEXCEPT ( Table1, Table1[Date] ) ), Table1[GroupOrder] IN { 3, 6, 9 }, VAR PreviousGroupOrder2_ = Table1[GroupOrder] - 2 RETURN CALCULATE ( DISTINCT ( Table1[Value 1] ), Table1[GroupOrder] = PreviousGroupOrder2_, ALLEXCEPT ( Table1, Table1[Date] ) ) )
AlB
6 years agoCommunity Champion
Since the introduction of VAR, there's no actual need for EARLIER any longer. So you might want to do it in a different way, perhaps easier to follow conceptually, and forget about EARLIER altogether (which is actually recommended nowadays):
Value2 =
SWITCH (
TRUE (),
Table1[GroupOrder] IN { 1, 4, 7 }, 0,
Table1[GroupOrder] IN { 2, 5, 8 },
VAR PreviousGroupOrder_ = Table1[GroupOrder] - 1
RETURN
CALCULATE (
DISTINCT ( Table1[Value 1] ),
Table1[GroupOrder] = PreviousGroupOrder_,
ALLEXCEPT ( Table1, Table1[Date] )
),
Table1[GroupOrder] IN { 3, 6, 9 },
VAR PreviousGroupOrder2_ = Table1[GroupOrder] - 2
RETURN
CALCULATE (
DISTINCT ( Table1[Value 1] ),
Table1[GroupOrder] = PreviousGroupOrder2_,
ALLEXCEPT ( Table1, Table1[Date] )
)
)
Destrogiro
6 years agoRegular Visitor
Thank you very much, AlB !
It solved my problem!