Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jeanso
Frequent Visitor

Doubts Last consumption

Hi Guys, i have a one problems with dax, 

preciso que seja exibido o penultimo numero de consumo de um item baseado na sua data de aplicação, por exemplo:
01/01/2022 2XX60 100 EQUIPAMENT 002
14/04/2022 2XX60 150 EQUIPAMENT 002
15/04/2022 2XX60 300 EQUIPAMENT 002

Bom nesse caso se eu filtrase apenas a data de 15/04 deveria me retornar 150 referente a 14/04, se eu filtrasse apenas a data de 13/04 deveria ser retornado 100 but my measure não funciona. se eu filtro apenas 13/04 não me exibe nenhum dado se eu filtro 14/04 me retorna 150 o que está errado deveria ser 100.

in atachment print from data.

Teste[date] would be the database, e calendar_1[date] the calendarexample.jpg

MAXX_ =
VAR MaxDate =
    CALCULATE ( MAX ( Teste[DATE] ), USERELATIONSHIP ( 'Calendar_1'[Date], Teste[DATE] ) )
VAR TableOnAndBefore =
    FILTER ( Teste, Teste[DATE] <= MaxDate )
VAR TableTopTwoDates =
    TOPN ( 2, TableOnAndBefore, Teste[Date] )
VAR Last2Value = SUMX ( TableTopTwoDates, Teste[WORKED HOURS] )
VAR MaxDateTable =
    FILTER ( TableTopTwoDates, Teste[Date] = MaxDate )
VAR LastValue = SUMX ( MaxDateTable, Teste[WORKED HOURS] )
VAR PenultimateValue = Last2Value - LastValue
VAR Result =
    PenultimateValue - LastValue
RETURN
    Result
0 REPLIES 0

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors