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

Running total column with many filters

I have table "Sales" (fields: Product, Country, Date, Sales) with monthly sales across many products and countries. Also I have tables with calendar, list of products, list of counties that are linked with this table. I want to add column to "Sales" with running total sales across each Product/Country, see the field with desired result "Running total".

 

I tried to use YTD = TOTALYTD(SUM(Sales[Sales]); Calendar[Date]) but it didn't work. I think I need to use filters in TOTALYTD function, but I also didn't manage to understand how. Can you suggest to me a right solution to my case?

 

 

ProductCountryDateSales,
tons
Running
total, tons
AUSJan-181010
AUSAug-18515
AUSFeb-192020
AUSMay-19525
ACanadaMar-1811
ACanadaDec-1834
ACanadaFeb-1977
ACanadaJun-191017
BUKFeb-1844
BUKSep-1815
BUKJan-1988
BUKOct-19412
BGermanyMar-181515
BGermanyNov-18318
BGermanyFeb-1977
BGermanyMay-1918
CJapanMar-182020
CJapanJul-181131
CJapanOct-1922
CJapanNov-1957
CKoreaFeb-1855
CKoreaMar-18712
CKoreaJun-1911
CKoreaJul-19910
1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Anonymous 

 

You may refer to the DAX below.

Column =
SUMX (
    FILTER (
        Sales,
        Sales[Product] = EARLIER ( Sales[Product] )
            && Sales[Country] = EARLIER ( Sales[Country] )
            && Sales[Date] <= EARLIER ( Sales[Date] )
            && YEAR ( Sales[Date] ) = YEAR ( EARLIER ( Sales[Date] ) )
    ),
    Sales[Sales]
)
Community Support Team _ Sam Zha
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

3 REPLIES 3
v-chuncz-msft
Community Support
Community Support

@Anonymous 

 

You may refer to the DAX below.

Column =
SUMX (
    FILTER (
        Sales,
        Sales[Product] = EARLIER ( Sales[Product] )
            && Sales[Country] = EARLIER ( Sales[Country] )
            && Sales[Date] <= EARLIER ( Sales[Date] )
            && YEAR ( Sales[Date] ) = YEAR ( EARLIER ( Sales[Date] ) )
    ),
    Sales[Sales]
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks, your solution was successful.

Anonymous
Not applicable

I partially coped with my issue by creating set of measures for each combination of product and country:

 

A_US = TOTALYTD(SUM(Sales[Sales]);'Calendar'[Date];FILTER(All(Sales);Sales[Product]="A"&&Sales[Country]="US"))

A_Canada = TOTALYTD(SUM(Sales[Sales]);'Calendar'[Date];FILTER(All(Sales);Sales[Product]="A"&&Sales[Country]="Canada"))

 

and so on.

 

But what if i have 100 products and 30 countries? I think I need to create a column "Running total" in "Sales" that calculates running total for each product and aech country.

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.