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
Anonymous
Not applicable

Help with comparting data dates

Hi,

 

I would like to do some calculations with the below data.

YTD - which I know I could use the TOTALYTD + Filter

 

TotalYTD - Actual = TOTALYTD(Sum('Table'[GM]),'Table'[Full Date],FILTER('Table','Table'[Measure Version]="Actual"))

 

 

But how do I do a calculation with the same date range ie m January -  September 2018 for the Plan and RF?

Also the total of last year for the same date range January -  September 2017?

 

Measure VersionGMFull Date
Actual$810988387.8501/01/2017 00:00
Actual$337791028.1301/02/2017 00:00
Actual$550435475.7601/03/2017 00:00
Actual$402794574.6601/04/2017 00:00
Actual$467615215.9801/05/2017 00:00
Actual$540032362.8301/06/2017 00:00
Actual$431805160.2501/07/2017 00:00
Actual$463675935.8301/08/2017 00:00
Actual$501191739.4101/09/2017 00:00
Actual$438198301.6801/11/2017 00:00
Actual$396214086.6001/12/2017 00:00
Actual$259308342.4901/01/2018 00:00
Actual$328621377.2701/02/2018 00:00
Actual$446070845.3701/03/2018 00:00
Actual$357567501.3601/04/2018 00:00
Actual$456199138.7601/05/2018 00:00
Actual$421862533.3701/06/2018 00:00
Actual$392615815.8201/07/2018 00:00
Actual$465390953.8301/08/2018 00:00
Actual$442974962.6501/09/2018 00:00
Plan$913421956.5701/01/2017 00:00
Plan$412362821.4501/02/2017 00:00
Plan$518063594.2301/03/2017 00:00
Plan$556249173.6801/04/2017 00:00
Plan$524580575.3801/05/2017 00:00
Plan$555159147.8501/06/2017 00:00
Plan$526988132.0401/07/2017 00:00
Plan$552664759.9701/08/2017 00:00
Plan$605712510.4401/09/2017 00:00
Plan$587320990.5901/11/2017 00:00
Plan$532713634.6201/12/2017 00:00
Plan$937890299.6001/01/2018 00:00
Plan$336840287.0601/02/2018 00:00
Plan$467714233.5501/03/2018 00:00
Plan$456025669.1601/04/2018 00:00
Plan$472688772.2801/05/2018 00:00
Plan$550095419.8601/06/2018 00:00
Plan$551625717.8901/07/2018 00:00
Plan$574777728.5901/08/2018 00:00
Plan$653631927.1301/09/2018 00:00
Plan$650477750.5001/11/2018 00:00
Plan$549065649.0201/12/2018 00:00
RF$767205034.6501/01/2018 00:00
RF$328621377.2701/02/2018 00:00
RF$446070845.3701/03/2018 00:00
RF$357567501.3601/04/2018 00:00
RF$456199138.7601/05/2018 00:00
RF$421862533.3701/06/2018 00:00
RF$392615815.8201/07/2018 00:00
RF$465390953.8301/08/2018 00:00
RF$607816648.6201/09/2018 00:00
RF$541901652.9201/11/2018 00:00
RF$514735218.3401/12/2018 00:00

 

Thank you 

1 ACCEPTED SOLUTION

Hi @Anonymous

The formula in your lastest post is correct to solve this problem.

So far, it is a useful workaround for your problem.

 

The penultimate one shows a incorrect formula.

MinDate =
CALCULATE (
MIN ( 'Table'[Full Date] ),
FILTER ( 'Table', 'Table'[Measure Version] = "Actual" ),
FILTER ( 'Table', 'Table'[Full Date] = YEAR ( 2018 ) ) //incorrect
)

Please see reference how to use "calculate" with "filter"

https://www.sqlbi.com/articles/filter-arguments-in-calculate/

 

If the formula is used in a measure, you could use the following instead.

YTD Plan =
VAR TableMaxDate =
    CALCULATE (
        MAX ( 'Table'[Full Date] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Measure Version] = "Actual" )
    )
VAR MinDate =
    CALCULATE (
        MIN ( 'Table'[Full Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Measure Version] = "Actual"
                && YEAR ( 'Table'[Full Date] ) = 2018  //from the information, it seems it is no 
need to add this part, if so,
you could delete this part
) ) RETURN CALCULATE ( SUM ( 'Table'[GM] ), FILTER ( 'Table', 'Table'[Measure Version] = "Plan" ), DATESBETWEEN ( DIM_Date[Date], MinDate, TableMaxDate ) )

Best Regards

Maggie

View solution in original post

22 REPLIES 22

Hi @Anonymous

The formula in your lastest post is correct to solve this problem.

So far, it is a useful workaround for your problem.

 

The penultimate one shows a incorrect formula.

MinDate =
CALCULATE (
MIN ( 'Table'[Full Date] ),
FILTER ( 'Table', 'Table'[Measure Version] = "Actual" ),
FILTER ( 'Table', 'Table'[Full Date] = YEAR ( 2018 ) ) //incorrect
)

Please see reference how to use "calculate" with "filter"

https://www.sqlbi.com/articles/filter-arguments-in-calculate/

 

If the formula is used in a measure, you could use the following instead.

YTD Plan =
VAR TableMaxDate =
    CALCULATE (
        MAX ( 'Table'[Full Date] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Measure Version] = "Actual" )
    )
VAR MinDate =
    CALCULATE (
        MIN ( 'Table'[Full Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Measure Version] = "Actual"
                && YEAR ( 'Table'[Full Date] ) = 2018  //from the information, it seems it is no 
need to add this part, if so,
you could delete this part
) ) RETURN CALCULATE ( SUM ( 'Table'[GM] ), FILTER ( 'Table', 'Table'[Measure Version] = "Plan" ), DATESBETWEEN ( DIM_Date[Date], MinDate, TableMaxDate ) )

Best Regards

Maggie

Anonymous
Not applicable

Ok, I have done the below;

 

 

Max Year Number = CALCULATE ( MAX ( 'Table'[Year] ), FILTER('Table','Table'[Measure Version]="Actual"))

 

 

 

YTD Plan = 
VAR TableMaxDate=
    CALCULATE ( MAX ( 'Table'[Full Date] ), FILTER('Table','Table'[Measure Version]="Actual" ) )
RETURN
    CALCULATE (
        Sum ('Table'[GM]), FILTER('Table','Table'[Measure Version]="Plan" ),DATESBETWEEN (DIM_Date[Date], DATE([Max Year Number],1,1) , TableMaxDate
            ))

It seems a little bit messy way of doing things but it got the right answer!

 

 

Do you think there is a better way to do this?

 

Thanks

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.