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
NathanSaber
New Member

Sum to Date

I'm having trouble calculating the Sum to Date when selecting a month from a Slicer.

 

The result I'm expecting is per table below when I select Feb from the Month Slicer

CategoryMonthTo Date
A3080
B100135

 

I've tried the following DAX formula for my To Date Measure, however it is returning the same results as the Month column above.

To Date =

CALCULATE(SUM(Transactions[Amount]),FILTER(ALL(Transactions[Period]),Transactions[Period] <= MAX(Transactions[Period])))

 

The details of the tables are below. They are linked via the Period field in both Tables. One to Many relationship (One - Period Table, Many - Transactions Table)

 

Transactions

PeriodAmountCategory
120A
130B
420A
410A
45B
840B
830A
860B
915A
925B
1210A
1230A

 

Period

PeriodMonth
1Jul
2Aug
3Sep
4Oct
5Nov
6Dec
7Jan
8Feb
9Mar
10Apr
11May
12Jun
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@NathanSaber , In case you have date prefer Time Intelligence

 

In This case, the Assume period is joined to Transaction. Ideally, In such cases you need to have the time/period table separately and use that

To Date =
CALCULATE(SUM(Transactions[Amount]),FILTER(ALL(Period),Period[Period] <= MAX(Period[Period])))

 

In case you have a Date, refer

Power BI — YTD
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @NathanSaber,

You can add a values function to your formula to simple group the rolling result based on the current category:

To Date =
CALCULATE (
    SUM ( Transactions[Amount] ),
    FILTER (
        ALLSELECTED ( Transactions[Period] ),
        Transactions[Period] <= MAX ( Transactions[Period] )
    ),
    VALUES ( Transactions[Category] )
)

DAX – The Many Faces of VALUES() 

BTW, I'd like to suggest you use allselected to replace all function if you want to keep original filter effects apply on your table:

Managing “all” functions in DAX: ALL, ALLSELECTED, ALLNOBLANKROW, ALLEXCEPT 
Regards,

Xiaoxin Sheng

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

@NathanSaber , In case you have date prefer Time Intelligence

 

In This case, the Assume period is joined to Transaction. Ideally, In such cases you need to have the time/period table separately and use that

To Date =
CALCULATE(SUM(Transactions[Amount]),FILTER(ALL(Period),Period[Period] <= MAX(Period[Period])))

 

In case you have a Date, refer

Power BI — YTD
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a

Greg_Deckler
Super User
Super User

@NathanSaber - Try

Measure =
  VAR __Category = MAX('Transactions'[Category])
  VAR __Period = MAX('Period'[Period])
RETURN
  SUMX(FILTER(ALL('Transactions'),[Category]=__Category && [Period]<=__Period),[Amount])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.