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
Sagejah9
Helper III
Helper III

Calculating the YTD of max of each month in a year

Hi ,

I am trying to calculate the year to date values for each month in a year but the max value 

 

I tried viking the max and then applied the ytd calculation but getting incorrect value.

2 ACCEPTED SOLUTIONS

Hi @Mikelytics 
Not necessarily

DescriptionAmountMonth-Year
Salaries90,302Jan-2020
Salaries90,302Jan-2020
Salaries90,302Jan-2020
Rent1,383Jan-2020
Rent1,383Jan-2020
Rent1,383Jan-2020
Salaries89,283Feb-2020
Salaries89,283Feb-2020
Salaries89,283Feb-2020
Rent1,221Feb-2020
Rent1,221Feb-2020
Rent1,221Feb-2020

 

Expected results YTD

DecriptionJan-2020Feb-2020
Salaries90,302179,585
Rent1,3832,604

 

I want to find either the max or average of the duplicates in each month and use that to calculate the year to date

 

View solution in original post

Hi @Sagejah9 ,

 

ok I think I understood. You want to extract per month the max value and use this in the YTD calculation right?

 

 

 

 

YTD of Monthly Max Item = 
TOTALYTD(
    SUMX(
        VALUES('Dim Date'[Year-Month]),
        CALCULATE(
           MAX([Amount])
        )
    )
    ,'Dim Date'[Date]
)

 

 

Mikelytics_6-1667373626978.png

 

Do you use a date table? Please be aware that you should use a Dim Date Table to make sure it works properly and follows best practices.
 

Best regards

Michael

 

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

 

 

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

5 REPLIES 5
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @Sagejah9 ,

 

Can you please give a little bit mor context what you want to achive? 

Do you want the monthly MAX or the Daily max? What granularity has your data.

 

I give you an example. Lets say you have data on daily basis. but you want to see for the year to date the value of the MONTH with the MAX value.

 

If this is your requirement you can do the following:

 

MAX Monthly Value YTD = 
TOTALYTD(
    MAXX(
        VALUES('Dim Date'[Month]),
        [SUM Sales]
    ),
    'Dim Date'[Date]
)

 

 

Mikelytics_0-1667328137354.png

 

Please be aware that you should use an additional Date dimension table to make sure that TOTALYTD works properly and follows best practices.

 

Best regards

Michael

 

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

 

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Hi @Mikelytics 
Not necessarily

DescriptionAmountMonth-Year
Salaries90,302Jan-2020
Salaries90,302Jan-2020
Salaries90,302Jan-2020
Rent1,383Jan-2020
Rent1,383Jan-2020
Rent1,383Jan-2020
Salaries89,283Feb-2020
Salaries89,283Feb-2020
Salaries89,283Feb-2020
Rent1,221Feb-2020
Rent1,221Feb-2020
Rent1,221Feb-2020

 

Expected results YTD

DecriptionJan-2020Feb-2020
Salaries90,302179,585
Rent1,3832,604

 

I want to find either the max or average of the duplicates in each month and use that to calculate the year to date

 

Hi @Sagejah9 ,

 

ok I think I understood. You want to extract per month the max value and use this in the YTD calculation right?

 

 

 

 

YTD of Monthly Max Item = 
TOTALYTD(
    SUMX(
        VALUES('Dim Date'[Year-Month]),
        CALCULATE(
           MAX([Amount])
        )
    )
    ,'Dim Date'[Date]
)

 

 

Mikelytics_6-1667373626978.png

 

Do you use a date table? Please be aware that you should use a Dim Date Table to make sure it works properly and follows best practices.
 

Best regards

Michael

 

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

 

 

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

@Sagejah9,

 

Please find attached a sample with your data example:

 

Your Sample

Mikelytics_1-1667378642626.png

 

Date Table

Mikelytics_2-1667378668432.png

Data model

Mikelytics_3-1667378702080.png

 

Measure and result

Mikelytics_0-1667378399006.png

 

Code:

YTD of Monthly Max Item = 
TOTALYTD(
    SUMX(
        VALUES('DimDate'[Year-Month]),
        CALCULATE(
           MAX('Sample'[Amount])
        )
    )
    ,'DimDate'[Date]
)

 

Best regards

Michael

 

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

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Hi @Sagejah9 ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create two measures as below to get it:

 

Measure = 
VAR _tab =
    SUMMARIZE (
        'Table',
        'Table'[Month-Year],
        'Table'[Description],
        'Table'[Amount]
    )
RETURN
    SUMX ( _tab, [Amount] )
Measure 2 = 
SUMX (
    FILTER (
        ALLSELECTED ( 'Table'[Month-Year] ),
        'Table'[Month-Year] <= SELECTEDVALUE ( 'Table'[Month-Year] )
    ),
    [Measure]
)

 

2. Create a matrix visual as below screenshot

yingyinr_1-1667372422946.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

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

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.