Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
tsql_simon
Helper I
Helper I

Filter a table by the aggregation of its self

I am struggling to filter a table by the aggregation of its self

Basically I have one Table which has a list of all payments as well a "zero" payment for the special few who get there subscription for free. The issue I am having is when I am trying to get
who is a "Paid" subscriber on a (by slicer) specific date. I have managed to get a cumulative total of Income and thought I had the count right till I realised I was not taking into account someone who may has a refund.

So from my table I would like to get the number of paid VIP subscribers on day X and for the same period the Year before

CompanyPayDatePayAmountIs VIPIs Zero PayerFinancial Year

AA0115/12/2019100102019
AA0212/12/2019100102019
AA0214/12/2019-100102019
AA0310/12/2019100102019
AA0405/12/201945002019
AA0501/12/20190112019
      
AA0115/12/2018100102018
AA0212/12/2018100102018
AA0310/12/2018100102018
AA0312/12/2018-100102018
AA0314/12/2018100102018
AA0405/12/201845002018
AA0501/12/20180112018

So from my table by the 12th Dec I would expect a count of 2 FOR 2019; AA02 has Paid AA03 Has paid and AA05 Is also counted as he is a special "Is Zero Payer"
and 2 for 2018 AA02 and AA05 as AA03 was refunded

Then for the 16th Dec I would expect 3 for 2019; AA01,AA03 and AA05 and 4 for 2018 AA01,AA02,AA03(paid,refunded,paid again) and AA05

AA04 never gets counted as they are not a VIP

Now in SQL I can Do this easily BY Filtering the table by aggregated sub query of itself (For reference our Financial year starts 1 Nov)

SELECT COUNT(DISTINCT Company) FROM MyTable
WHERE Company NOT IN (SELECT Company FROM MyTable WHERE PayDate Between '20191101' and '20191212' GROUP BY Company HAVING SUM(PayAmount) >0 )
and PayDate Between '20191101' and '20191212'
and [Is Vip] = 1

1 ACCEPTED SOLUTION
v-lid-msft
Community Support
Community Support

Hi @tsql_simon ,

 

We can create a measure to meet your requirement:

 

CountNumber =
COUNTROWS (
    FILTER (
        SUMMARIZE (
            FILTER ( 'Table', [Is VIP] = 1 ),
            'Table'[Company],
            "Total", SUM ( 'Table'[PayAmount] ),
            "IsZero", MIN ( 'Table'[Is Zero Payer] )
        ),
        [Total] > 0
            || [IsZero] = 0
    )
)

 

18.jpg19.jpg

 


If it doesn't meet your requirement, Please show the exact expected result based on the Tables that you have shared.

 


Best regards,

 

Community Support Team _ Dong Li
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-lid-msft
Community Support
Community Support

Hi @tsql_simon ,

 

We can create a measure to meet your requirement:

 

CountNumber =
COUNTROWS (
    FILTER (
        SUMMARIZE (
            FILTER ( 'Table', [Is VIP] = 1 ),
            'Table'[Company],
            "Total", SUM ( 'Table'[PayAmount] ),
            "IsZero", MIN ( 'Table'[Is Zero Payer] )
        ),
        [Total] > 0
            || [IsZero] = 0
    )
)

 

18.jpg19.jpg

 


If it doesn't meet your requirement, Please show the exact expected result based on the Tables that you have shared.

 


Best regards,

 

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

That works perfectly, 3 days I did not think to aggregate the Boolean filed Doh! you are a God amongst us mere mortals your help is invaluable

 

Kindest Regards

Simon Richardson

mwegener
Most Valuable Professional
Most Valuable Professional

Hi @tsql_simon ,

 

check this out. SUMMARIZE your Data and FILTER on it.

 

Measure = COUNTROWS(FILTER(SUMMARIZE(MyTable,MyTable[Company],MyTable[Is VIP],"Sum of Payment",SUM(MyTable[PayAmount])),[Sum of Payment] > 0))

 

 

If I answered your question, please mark my post as solution, this will also help others.

Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors