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

Calculate SUM for latest Financial Month in a Year, grouped by various columns

Hi All,

 

I have below table:

 

Shreyansh_0-1620719974259.png

 

I want to calculate SUM of Value for latest Financial Year, for every year grouped by Country and Businees Vertical for Scenario = "Forecasted - Yearly"

I am currently using this DAX query, but it is not working right:

 

Measure =
VAR LastNonBlankDate =
    CALCULATE (
        MAXA ( 'Planned and Realized'[Date] ),
        FILTER (
            ALL ( 'Planned and Realized' ),
            'Planned and Realized'[Date] <= MAXA ( 'Planned and Realized'[Date] )
                && 'Planned and Realized'[Value] > 0
                && 'Planned and Realized'[Scenario] = "Forecasted - Yearly"
        )
    )
RETURN
    CALCULATE (
        SUMX ( 'Planned and Realized', 'Planned and Realized'[Value] ),
        FILTER (
            ALL ( 'Planned and Realized' ),
            'Planned and Realized'[Date] = LastNonBlankDate
                && 'Planned and Realized'[Scenario] = "Forecasted - Yearly"
                && 'Planned and Realized'[Account] = "Revenue"
        )
    )

 

But it is giving me wrong result, see this :

Shreyansh_1-1620720335291.png

I also tried to create a new table with DAX, but I could not get data for all years, it only shows for latest year:

 

Latest Forecast revenue =
VAR LastNonBlankDate =
    CALCULATE (
        MAXA ( 'Planned and Realized'[Date] ),
        FILTER (
            ALL ( 'Planned and Realized' ),
            'Planned and Realized'[Date] <= MAXA ( 'Planned and Realized'[Date] )
                && 'Planned and Realized'[Value] > 0
                && 'Planned and Realized'[Scenario] = "Forecasted - Yearly"
        )
    )
RETURN
    SUMMARIZE (
        FILTER (
            ALL ( 'Planned and Realized' ),
            'Planned and Realized'[Date] = LastNonBlankDate
                && 'Planned and Realized'[Scenario] = "Forecasted - Yearly"
                && 'Planned and Realized'[Account] = "Revenue"
        ),
        'Planned and Realized'[Country],
        'Planned and Realized'[Date],
        'Planned and Realized'[Scenario],
        'Planned and Realized'[Business Vertical],
        "Total Sales"SUM ( 'Planned and Realized'[Value] )
    )

 

See the result:

Table:

Shreyansh_2-1620720505743.png

 

Result:

Shreyansh_3-1620720559742.png

 

How can I get it working for all the years, and not only latest year ?

 

Thanks in advance

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , You can use time intelligence and date table 

Three measures  like 

measure =
CALCULATE (
SUMX ( 'Planned and Realized', 'Planned and Realized'[Value] ),
FILTER (
( 'Planned and Realized' ),
'Planned and Realized'[Scenario] = "Forecasted - Yearly"
&& 'Planned and Realized'[Account] = "Revenue"
)
)

 

YTD = CALCULATE([measure],DATESYTD('Date'[Date],"12/31"))
Last YTD = CALCULATE([measure],DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , You can use time intelligence and date table 

Three measures  like 

measure =
CALCULATE (
SUMX ( 'Planned and Realized', 'Planned and Realized'[Value] ),
FILTER (
( 'Planned and Realized' ),
'Planned and Realized'[Scenario] = "Forecasted - Yearly"
&& 'Planned and Realized'[Account] = "Revenue"
)
)

 

YTD = CALCULATE([measure],DATESYTD('Date'[Date],"12/31"))
Last YTD = CALCULATE([measure],DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

Anonymous
Not applicable

Hi @amitchandak ,

 

Thanks for the reply, I managed to get most of my issue solved, but still one problem remains.

I think I fogot to mention in my original post, but what I exactly want is sum of values for the latest month in a financial year for all years.

So after your recommendation, I create a date table with starting month as October, and ending month September from 2017-2021, I managed to get different sum for different years, Country etc.

But for eg, if I have data till April 2021, this year, and I also have data for March, Feb etc in 2021, then I don't want to SUM data from March, feb etc, for this year, only SUM the data for latest Month in a Financial year, for every year. In screenshot below, I don't want to SUM March, but only April, as it is the only latest month available in that year

Screenshot 2021-05-12 125101.png

 

Hope you got my query.

 

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.

Top Solution Authors