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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.