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
AleFVG
Helper I
Helper I

Sum Groupby only for current year

Hello guys!

 

i have this dax formula:

 

ABC by Year = GROUPBY('Fact','Fact'[Supplier],"Spend",SUMX(CURRENTGROUP(),'Fact'[Spend]))

 

 

how can i change it because i only sum the values of the current year (with time intelligence)? and not, like the written formula, sum all the values for the years present in the fact table.

 

many thanks

 

 

 

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

Hi @AleFVG ,

Here is my data sample and pbix file.

2020-1-11
2019-1-12
2019-1-13
2018-2-24
2018-3-25
2020-1-16

 

In my test, your GROUPBY() formula returns a new table like this:

11.5.2.1.PNG

According to my understand, you want to calculate the sum of each year, or just the current year(2020) , right?

You could use the following formula:

Measure =
CALCULATE (
    SUM ( 'Table1'[Value] ),
    FILTER ( ALL ( 'Table1' ), 'Table1'[Year] = MAX ( 'Table1'[Year] ) )
)
SumCurrentYear =
IF (
    MAX ( 'Table1'[Year] ) = YEAR ( TODAY () ),
    CALCULATE (
        SUM ( 'Table1'[Value] ),
        FILTER ( ALL ( 'Table1' ), 'Table1'[Year] = YEAR ( TODAY () ) )
    )
)

Or create a column

Column =
CALCULATE ( SUM ( 'Table1'[Value] ), ALLEXCEPT ( Table1, Table1[Year] ) )

My visualizations are shown below:

11.5.2.2.PNG

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

View solution in original post

4 REPLIES 4
v-eqin-msft
Community Support
Community Support

Hi @AleFVG ,

 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.

 

Best Regards,
Eyelyn Qin

v-eqin-msft
Community Support
Community Support

Hi @AleFVG ,

Here is my data sample and pbix file.

2020-1-11
2019-1-12
2019-1-13
2018-2-24
2018-3-25
2020-1-16

 

In my test, your GROUPBY() formula returns a new table like this:

11.5.2.1.PNG

According to my understand, you want to calculate the sum of each year, or just the current year(2020) , right?

You could use the following formula:

Measure =
CALCULATE (
    SUM ( 'Table1'[Value] ),
    FILTER ( ALL ( 'Table1' ), 'Table1'[Year] = MAX ( 'Table1'[Year] ) )
)
SumCurrentYear =
IF (
    MAX ( 'Table1'[Year] ) = YEAR ( TODAY () ),
    CALCULATE (
        SUM ( 'Table1'[Value] ),
        FILTER ( ALL ( 'Table1' ), 'Table1'[Year] = YEAR ( TODAY () ) )
    )
)

Or create a column

Column =
CALCULATE ( SUM ( 'Table1'[Value] ), ALLEXCEPT ( Table1, Table1[Year] ) )

My visualizations are shown below:

11.5.2.2.PNG

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

amitchandak
Super User
Super User

@AleFVG , With a date table with time intelligence

example

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

 

//Can work with year table too

This Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

thanks for your response @amitchandak !

 

I have date table, but i didn't understand how i should change my dax formula.

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