Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
abhay03
Helper I
Helper I

Sum of values by date for each category

In my report, there is a report-level filter on the current month. I have to show the values of Amount for each category side by side for 2 different time period: first for the current month and for 2 months prior. Below are the two tables:

 

DimCategory

Key

Category
1ABC
2DEF
3GHI

 

FactCategory

KeyAmountDate
11009/01/2017
22009/01/2017
23009/11/2017
34009/01/2017
15010/01/2017
26010/02/2017
37010/11/2017
18011/15/2017
29011/16/2017
38011/17/2017
37011/18/2017

 

I tried writing measure to calculate two months prior Amount for each category but the result I am getting is the sum of all category for that time period. 

 

Measure = CALCULATE(SUM(FactCategory[Amount]), 
FILTER(ALL(FactCategory), MONTH(FactCategory[Date]) = 9)) Measure 2 = SUMX( SUMMARIZE( FactCategory, DimCategory[Category], "VALUE", CALCULATE(SUM(FactCategory[Amount]), FILTER(ALL(FactCategory), MONTH(FactCategory[Date]) = 9)) ), [VALUE] )

 

image.png 

 

How can I get the below output:

CategoryAmountAmount 2 months prior
ABC8010
DEF9050
GHI15040
1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @abhay03,

 

You can try to use below formula to get previous data.

 

Measure:

Previous 2 Month =
VAR current_Date =
    MAX ( FactCategory[Date] )
RETURN
    SUMX (
        FILTER (
            ALL ( FactCategory ),
            [Key] = MAX ( DimCategory[Key] )
                && FORMAT ( [Date], "yyyy mmm" )
                    = FORMAT (
                        DATE ( YEAR ( current_Date ), MONTH ( current_Date ) - 2, 1 ),
                        "yyyy mmm"
                    )
        ),
        [Amount]
    )

1.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @abhay03,

 

You can try to use below formula to get previous data.

 

Measure:

Previous 2 Month =
VAR current_Date =
    MAX ( FactCategory[Date] )
RETURN
    SUMX (
        FILTER (
            ALL ( FactCategory ),
            [Key] = MAX ( DimCategory[Key] )
                && FORMAT ( [Date], "yyyy mmm" )
                    = FORMAT (
                        DATE ( YEAR ( current_Date ), MONTH ( current_Date ) - 2, 1 ),
                        "yyyy mmm"
                    )
        ),
        [Amount]
    )

1.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thanks, @v-shex-msft. This is exactly what I was looking for.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.