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

Get 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

Reply
raffa_pintto1
Regular Visitor

Variação dia vs dia

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

 

 

foto .jpg

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @raffa_pintto1 ,

 

Here I create a sample to have a test.

vrzhoumsft_0-1695289505497.png

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.

vrzhoumsft_1-1695289764578.png

 

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.

View solution in original post

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @raffa_pintto1 ,

 

Here I create a sample to have a test.

vrzhoumsft_0-1695289505497.png

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.

vrzhoumsft_1-1695289764578.png

 

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.

lbendlin
Super User
Super User

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...

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

Top Solution Authors