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
a1enas
Regular Visitor

Sum of value by date year ago and filtered by another key

HI!

 

I have the same data in table:

DATENUMBERIDSUM
01.01.201811550
01.01.2018110111000
01.01.2018241500
01.01.201833200
02.01.201824700
02.01.20182204600
03.01.201833300
............

 

and I need to calculate the total sum for every NUMBER by DATE year ago. How i can do it?

I created column with _PREV_DATE and tried to use: 

=calculate(
SUM(table[SUM);
        filter(table;
table[DATE]=table[_PREV_DATE] && table[NUMBER]=table[NUMBER]))
 

but it failed (blank), what am i doing wrong?

so i want something like this (may be it can be measure, not calculated column):

DATENUMBERIDSUMSUM YEAR AGO
01.01.201811550800
01.01.2018110111000800
01.01.2018241500600
01.01.2018332001500
02.01.201824700750
02.01.20182204600750
03.01.201833300100
1 ACCEPTED SOLUTION
v-cherch-msft
Employee
Employee

Hi @a1enas 

You may create a measure like below:

Measure = 
VAR _pre =
    DATE ( YEAR ( MAX ( Table1[Date] ) ) - 1, MONTH ( MAX ( Table1[Date] ) ), DAY ( MAX ( Table1[Date] ) ) )
RETURN
    CALCULATE (
        SUM ( Table1[SUM] ),
        FILTER (
            ALL ( Table1 ),
            Table1[Date] = _pre
                && Table1[Number] = MAX ( Table1[Number] )
        )
    )

1.png

Regards,

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

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Ensure that the entreis in the Date column are actual date entries (so replace . with /).  Create a Calendar Table and build a relationship from the Date column of the Data Table with the Date column of the Calendar Table.  In the Calendar Table, extract Year and Months using the following calculated column formulas.  Year = Year(Calendar[Date]) and Month = FORMAT(Calendar[Date],"mmmm").  To your visual, drag Year and Month from the Calendar Table and Number, ID from the Data Table.  Write the following measures

Total = SUM(Data[Sum])

Total LY = CALCULATE([Total],PREVIOUSYEAR(Calendar[Date])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-cherch-msft
Employee
Employee

Hi @a1enas 

You may create a measure like below:

Measure = 
VAR _pre =
    DATE ( YEAR ( MAX ( Table1[Date] ) ) - 1, MONTH ( MAX ( Table1[Date] ) ), DAY ( MAX ( Table1[Date] ) ) )
RETURN
    CALCULATE (
        SUM ( Table1[SUM] ),
        FILTER (
            ALL ( Table1 ),
            Table1[Date] = _pre
                && Table1[Number] = MAX ( Table1[Number] )
        )
    )

1.png

Regards,

Community Support Team _ Cherie Chen
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.