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
jechris
Frequent Visitor

Filtering and ADDCOLUMNS field containing a cumulative sum/total

I am trying to filter a table based on a cummulative sum/total which is calculated and added as an ADDCOLUMNS field.

I want find the smallest bin ("Table"[Bits]) with the) that contains a count above a specific number (in this example 30)

MEASURE= SELECTCOLUMNS(
    TOPN(1,
        TOPN(1,
            FILTER(
                ADDCOLUMNS(
                    'Table',
                    "CumSum",
                    CALCULATE (
                        SUM ( 'Table'[Count] ),
                        FILTER (
                            ALL ( 'Table'[Bits] ),
                            'Table'[Bits] <= MAX ( 'Table'[Bits] )
                        )
                    )
                ),
                [CumSum] > 30
            ),
            [CumSum],ASC
        ),
        [Bits],ASC
    ),
    "temp", 'Table'[Bits]
)

I want to be able to do this for any set of months. 

 

MonthBitsCount
105
11020
1202
1301
1404
1503
1808
2201
2301
2603
3105
3306


Capture3.PNG

 

The expected result in this case (for all months/no filtering) is 20 Bits... since that is the first instance where the cumulative sum exceeds 30 (in this case 33 is the total).

 

I can't get this to work and the cumulative sum is never calculated for each bit bucket.

 

Please help

7 REPLIES 7
Phil_Seamark
Employee
Employee

Hi @jechris

 

I think this calculated measure might be close

 

Measure = 
VAR t = ADDCOLUMNS(
                    'Table',
                    "CumSum",
                    CALCULATE (
                        SUM ( 'Table'[Count] ),
                        FILTER (
                            ALL ( 'Table' ),
                            'Table'[Bits] <= EARLIER( 'Table'[Bits] )
                        )
                    )
				)
VAR x = FILTER(t,[CumSum]>30)
VAR z = MINX(x,[Bits])
RETURN z

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

@Phil_Seamark

Thank you for your solution. 
It seems to work well when no filters are applied but if I select a specific Month, say "2".
Capture4.PNG

In this example I want to find the first Bit column where the cumulative sum is above 3. This should be 60 Bits in this case.

Is there a reason why these filters doesn't quite apply correctly to the page?

Thank you
Jens Christensen

Phil_Seamark
Employee
Employee

Hi @jechris

 

When you say "since that is the first instance where the cumulative sum exceeds 30 (in this case 33 is the total)."

 

How do you arrive at the value of 33?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi @Phil_Seamark

Sorry for not making that clear.

The cumulative sums for 20 bits is the sum of the counts in bold below from the table:
(5) + (20 + 5) + (2 + 1) = 33
That is the sum for each bin of bits for any all months.
(0 bit count) + (10 bit count) + (20 bit count) = cumulative sum at 20 bits.  

 

MonthBitsCount
105
11020
1202
1301
1404
1503
1808
2201
2301
2603
3105
3306

Hi @jechris,

 

So in a simpple card visual, do you want the answer to be 30?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur

Yes, correct.

Regards

Jens Christensen

Hi @jechris,

 

Sorry for taking so much time to respond.  I think i have a solution.  You may download my workbook from here.  While i have formulated this solution in MS Excel, one can do this in PowerBI desktop as well (or else you can directly also import this workbook to PowerBI desktop).

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.