Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Incorrect matrix total for YTD

I have a matrix for countries, cities and YTD, but the YTD for the total and subtotals for countries is wrong. Here are the tables and measure:
CityCost table

CountryCityCostDate
UKLondon178701/01/2023
UKLondon902/01/2023
UKLondon26703/01/2023
UK

Manchester

-19901/01/2023
UKManchester-18202/01/2023
UKManchester111303/01/2023
UKLiverpool63801/01/2023
UKLiverpool182402/01/2023
UKLiverpool119803/01/2023
UKLiverpool160604/01/2023
GermanyBerlin126501/01/2023
GermanyBerlin9402/01/2023
GermanyMunchen22701/01/2023
GermanyMunchen119902/01/2023
GermanyMunchen63303/01/2023
FranceParis192601/01/2023
FranceParis34902/01/2023
FranceParis98703/01/2023
FranceParis117804/01/2023

 

DayCost table

DateDayCost
01/01/2023994140
02/01/20231293186
03/01/20231438443
04/01/20231291846

 

YTD =
CALCULATE(
    divide(
        Sum(
            'CityCost'[Cost]
        ),
        sum(
            DayCost[DayCost]
        )
    )+0,
    DATESYTD(
        DayCost[Date]
    )
)
 
Current output:
How it should be:
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) My test data is the same as yours.

    (2) We can create a measure. 

    TOTAL_YTD = SUMX(VALUES('CityCost'[Country]),[YTD])

    (3) Then the result is as follows.

    Best Regards,

    Neeko Tang

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

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) My test data is the same as yours.

    (2) We can create a measure. 

    TOTAL_YTD = SUMX(VALUES('CityCost'[Country]),[YTD])

    (3) Then the result is as follows.

    Best Regards,

    Neeko Tang

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