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
Justas4478
Post Patron
Post Patron

Modifying cumulative measure

Hi, I have Cumulative sales measure that is working fine for simple cases. But when I apply date filter to table visual in power bi. This measure starts to ignore all the sales that happened before date set in the filter. I tried to use ALLEXCEPT and ALLSELECTED DAX but I cant get it to work. This is the measure. Just to note 'Actuals'[Sales Volume] is measure not a column.

 

Cumulative Sales volume =
var _min = date(2021,06,01)

return
CALCULATE (
'Actuals'[Sales Volume],
FILTER (
ALLSELECTED ( 'Date' ),
'Date'[Date]<= MAX ( 'Date'[Date] ) && 'Date'[Date]>= _min
))
 This line "var _min = date(2021,06,01)" tells from when sales should be shown in the table. And as you can see it works but the problem is that it as well ignores all the sales before that date.
Cumulative sales.PNG
I would like to be able to filter table to limit amount of rows I need to look at. But the measure sould be able to get the past sales data and calculate them in to the results on the table.
From what I know I think it should be possible.
If there is anything unclear just let me know.
Thank you.
1 ACCEPTED SOLUTION

Hi, @Justas4478 

 

What you want to achieve is to calculate a cumulative total from a set minimum date to the maximum date in the table, regardless of how the table visual is filtered?
Try to modify your measures as follows:

_Cumulative Sales volume = 
VAR _min =
    DATE( 2021, 06, 01 )
var _max=CALCULATE(MAX('Table1'[Date]),ALL(Table1))
RETURN
    CALCULATE(
        [_Sales Volume],
        FILTER(
            ALL('Table1' ),
            'Table1'[Date] <= _max
                && 'Table1'[Date] >= _min
        )
    )

Result:

vangzhengmsft_0-1642557696423.png

Please refer to the attachment below for details.

Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng

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

8 REPLIES 8
v-angzheng-msft
Community Support
Community Support

Hi, @Justas4478 

So what you want to achieve is to calculate the running total from the filtered date? Then you only need to modify the ALL function in the above code to the ALLSELECTED function, as follows:

Cumulative Sales volume = 
CALCULATE([Sales Volume],FILTER(ALLSELECTED(Table2),'Table2'[Date]<=MAX('Table2'[Date])))

Result:

vangzhengmsft_0-1642473102411.png

 

If this is not the result you want, could you please posting expected result so it is clear on what needs to be implemented?  And It would be great if there is a sample file without any sesentive information here.

It makes it easier to give you a solution.

  1. Sample (dummy dataset) data as text, use the table tool in the editing bar
  2. Expected output from sample data
  3. Explanation in words of how to get from 1. to 2.

 

Hope this helps.

 

Best Regards,
Community Support Team _ Zeon Zheng

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-angzheng-msft 

1: This is link to sample file. https://we.tl/t-bQ1Q15qP8C 

2: I wrote expected outputs in the sample file, but will write it here as well.

Sales Volume total - 11,812,413

Expected Cumulative sales volume total - 11,810,594

Cumulative sales total should stay 11,810,594 even if table is filtered just to show December mont only.

3: Measure should caculate cumulative sales starting from 01/06/2021 any sales before this date should be ingnored by the measure. Measure should still be able to calculate sales even if table visual is filtered to only show december month for the user. Which is where it fails to work.

Since measure stops calculating any data before december. It should ignore December filter placed by the user but still obey to 01/06/2021 date and calculate sales only starting from this date.

Hi, @Justas4478 

 

What you want to achieve is to calculate a cumulative total from a set minimum date to the maximum date in the table, regardless of how the table visual is filtered?
Try to modify your measures as follows:

_Cumulative Sales volume = 
VAR _min =
    DATE( 2021, 06, 01 )
var _max=CALCULATE(MAX('Table1'[Date]),ALL(Table1))
RETURN
    CALCULATE(
        [_Sales Volume],
        FILTER(
            ALL('Table1' ),
            'Table1'[Date] <= _max
                && 'Table1'[Date] >= _min
        )
    )

Result:

vangzhengmsft_0-1642557696423.png

Please refer to the attachment below for details.

Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-angzheng-msft Looks like it worked. Thank you so much.

v-angzheng-msft
Community Support
Community Support

Hi, @Justas4478 

Try to create a measure like this:

Cumulative Sales volume = 
CALCULATE([Sales Volume],FILTER(ALL(Table2),'Table2'[Date]<=MAX('Table2'[Date])))

Result:

vangzhengmsft_0-1642392532141.png

The measure will not ignore previous sales no matter how you filter the data.

 

If this doesn't work for you, could you please consider sharing more details about it and posting expected result so it is clear on what needs to be implemented?  And It would be great if there is a sample file without any sesentive information here.

 

 

Best Regards,
Community Support Team _ Zeon Zheng

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@amitchandak Hi This solution works. But it as well calculates sales before var _min = date(2021,06,01) date. which are not required for the table and that results in much higer sales numbers than actual. I dont know is it possible to keep the effects of the solution you just wrote and to have as well limitation of this date(2021,06,01).

amitchandak
Super User
Super User

@Justas4478 ,Try with all

 

Cumulative Sales volume =
var _min = date(2021,06,01)

return
CALCULATE (
'Actuals'[Sales Volume],
FILTER (
ALL( 'Date' ),
'Date'[Date]<= MAX ( 'Date'[Date] ) && 'Date'[Date]>= _min
))

@amitchandak Hi, I just tried it and still gives same result in totals and in rows.

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.