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
John_Silva642
Frequent Visitor

Filtering DATESBETWEEN with LASTDATE

Hello,

I'm having a problem filtering this measure with the DATESBETWEEN.
How can I fix this measure, and what's the issue?

VAR DATAMAX =
CALCULATE(
LASTDATE(RE[Data]),
RE[Informações] = "Contratos Negociados"
)
VAR RESULT =
CALCULATE(
SUM(RE[Valor]),
RE[Informações] = "Contratos Negociados",
DATESBETWEEN(
RE[Data],
LASTDATE(
DATEADD(RE[Data],
-12,
MONTH
)
),
DATAMAX
)
)
RETURN
RESULT


Table:

John_Silva642_0-1638405660624.png

 

I need some of the last thirteen months' average that is 102.

But this measure it's returning 56 as result (it's some of the last six values).

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

Hi @John_Silva642 ,

 

Transpose table in power query, convert the data model formed by the date column. After testing the following code, the results returned are correct. Can you provide more information or test data so that I can answer your questions as soon as possible.

vstephenmsft_0-1638781765622.png

vstephenmsft_1-1638781773005.png

vstephenmsft_2-1638781790628.png

sum_total = 
VAR DATAMAX =
    CALCULATE ( LASTDATE ( 'RE'[Date] ), 'RE'[Informações] = "Contratos Negociados" )
VAR RESULT =
    CALCULATE (
        SUM ( 'RE'[Value] ),
        'RE'[Informações] = "Contratos Negociados",
        DATESBETWEEN (
            'RE'[Date],
            LASTDATE ( DATEADD ( 'RE'[Date], -13, MONTH ) ),
            DATAMAX
        )
    )
RETURN
RESULT


Best Regards,
Stephen


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-stephen-msft
Community Support
Community Support

Hi @John_Silva642 ,

 

Transpose table in power query, convert the data model formed by the date column. After testing the following code, the results returned are correct. Can you provide more information or test data so that I can answer your questions as soon as possible.

vstephenmsft_0-1638781765622.png

vstephenmsft_1-1638781773005.png

vstephenmsft_2-1638781790628.png

sum_total = 
VAR DATAMAX =
    CALCULATE ( LASTDATE ( 'RE'[Date] ), 'RE'[Informações] = "Contratos Negociados" )
VAR RESULT =
    CALCULATE (
        SUM ( 'RE'[Value] ),
        'RE'[Informações] = "Contratos Negociados",
        DATESBETWEEN (
            'RE'[Date],
            LASTDATE ( DATEADD ( 'RE'[Date], -13, MONTH ) ),
            DATAMAX
        )
    )
RETURN
RESULT


Best Regards,
Stephen


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

John_Silva642
Frequent Visitor

*I need some of the last thirteen months' values that is 102.

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