Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Boa Tarde
Estou fazendo esse calculo dax no qual tenho uma base de dados onde alguns dias da semana tem o preenchimento com dados e outros não. Preciso que quando não tiver dados eu pego os dados do dia anterior. Exemplo nos meus dados
dia
15/09
14/09
13/09
12/09
10/09
09/09
08/09
Estou no dia 12/09 não tenho dados do dia 11/09 e 10/09 então no meu meu dax está dando 100% eu preciso que ele pegue o dados do dia 09/09 que seria o ultimo dia que tenho dados e faça variação percentual
Solved! Go to Solution.
Hi @raffa_pintto1 ,
Here I create a sample to have a test.
Measure:
M_ULTIMO km =
VAR _STEP1 =
ADDCOLUMNS (
ALL('Calendar'),
"km",
CALCULATE (
SUM ( 'Table'[ULTIMO km] ),
USERELATIONSHIP ( 'Table'[Data Brev], 'Calendar'[Date] )
),
"km last day",
CALCULATE (
SUM ( 'Table'[ULTIMO km] ),
FILTER ( 'Table', 'Table'[Data Brev] = EARLIER ( 'Calendar'[Date] ) - 1 )
)
)
VAR _STEP2 =
ADDCOLUMNS (
_STEP1,
"New km",
VAR _LASTNOTBLANK =
MAXX (
FILTER ( _STEP1, [Date] <= EARLIER ( [Date] ) && [km] <> BLANK () ),
[Date]
)
VAR _KM =
SUMX ( FILTER ( _STEP1, [Date] = _LASTNOTBLANK ), [km] )
RETURN
_KM
)
RETURN
SUMX(FILTER(_STEP2,[Date] =MAX('Calendar'[Date])),[New km])
M_D X D =
VAR _STEP1 =
ADDCOLUMNS (
ALL('Calendar'),
"km",
CALCULATE (
SUM ( 'Table'[ULTIMO km] ),
USERELATIONSHIP ( 'Table'[Data Brev], 'Calendar'[Date] )
),
"D X D",
CALCULATE (
SUM ( 'Table'[ULTIMO km] ),
FILTER ( 'Table', 'Table'[Data Brev] = EARLIER ( 'Calendar'[Date] ) - 1 )
)
)
VAR _STEP2 =
ADDCOLUMNS (
_STEP1,
"New DXD",
VAR _LASTNOTBLANK =
MAXX (
FILTER ( _STEP1, [Date] <= EARLIER ( [Date] ) && [D X D] <> BLANK () ),
[Date]
)
VAR _DXD =
SUMX ( FILTER ( _STEP1, [Date] = _LASTNOTBLANK ), [D X D] )
RETURN
_DXD
)
RETURN
SUMX(FILTER(_STEP2,[Date] =MAX('Calendar'[Date])),[New DXD])
M_%Mom dia =
DIVIDE([M_ULTIMO km] - [M_D X D],[M_D X D])
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @raffa_pintto1 ,
Here I create a sample to have a test.
Measure:
M_ULTIMO km =
VAR _STEP1 =
ADDCOLUMNS (
ALL('Calendar'),
"km",
CALCULATE (
SUM ( 'Table'[ULTIMO km] ),
USERELATIONSHIP ( 'Table'[Data Brev], 'Calendar'[Date] )
),
"km last day",
CALCULATE (
SUM ( 'Table'[ULTIMO km] ),
FILTER ( 'Table', 'Table'[Data Brev] = EARLIER ( 'Calendar'[Date] ) - 1 )
)
)
VAR _STEP2 =
ADDCOLUMNS (
_STEP1,
"New km",
VAR _LASTNOTBLANK =
MAXX (
FILTER ( _STEP1, [Date] <= EARLIER ( [Date] ) && [km] <> BLANK () ),
[Date]
)
VAR _KM =
SUMX ( FILTER ( _STEP1, [Date] = _LASTNOTBLANK ), [km] )
RETURN
_KM
)
RETURN
SUMX(FILTER(_STEP2,[Date] =MAX('Calendar'[Date])),[New km])
M_D X D =
VAR _STEP1 =
ADDCOLUMNS (
ALL('Calendar'),
"km",
CALCULATE (
SUM ( 'Table'[ULTIMO km] ),
USERELATIONSHIP ( 'Table'[Data Brev], 'Calendar'[Date] )
),
"D X D",
CALCULATE (
SUM ( 'Table'[ULTIMO km] ),
FILTER ( 'Table', 'Table'[Data Brev] = EARLIER ( 'Calendar'[Date] ) - 1 )
)
)
VAR _STEP2 =
ADDCOLUMNS (
_STEP1,
"New DXD",
VAR _LASTNOTBLANK =
MAXX (
FILTER ( _STEP1, [Date] <= EARLIER ( [Date] ) && [D X D] <> BLANK () ),
[Date]
)
VAR _DXD =
SUMX ( FILTER ( _STEP1, [Date] = _LASTNOTBLANK ), [D X D] )
RETURN
_DXD
)
RETURN
SUMX(FILTER(_STEP2,[Date] =MAX('Calendar'[Date])),[New DXD])
M_%Mom dia =
DIVIDE([M_ULTIMO km] - [M_D X D],[M_D X D])
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
You do that using disconnected tables.
Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.
https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
26 | |
20 | |
19 | |
14 | |
13 |
User | Count |
---|---|
43 | |
36 | |
24 | |
23 | |
21 |