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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
ohnothimagain
Helper I
Helper I

How to filter with dynamic Array based on calculation

Hello everyone.

I need to filter this table with conditions;  summarize [PN] and except [@diff]values lower than zero.

I tried some practices and spent hours,but filter affected to each row,[warehouse]AAAA didin't appears...
How should I correct it....?

■TABLE

ohnothimagain_1-1727096255152.png

■DAX

 

test11:=
var _sum=SUMMARIZE('TEST_','TEST_'[PN],"@Qty",SUM(TEST_[Qty]),"@Req",sum(TEST_[Req]))
var _add=ADDCOLUMNS(_sum,"@diff",[@Qty]-[@Req])
var _ftd=filter(_add,[@diff]>0)
var _Trg=SELECTCOLUMNS(_ftd,"@PN",[PN])
var _result=calculate(countrows(TEST_),'TEST_'[PN] IN _Trg)
//var _result=calculate(countrows(TEST_),filter('TEST_','TEST_'[PN] IN {"X-0002-000-1000","X-0002-000-1002"}))  result expected

return
_result

 


■Result
ohnothimagain_0-1727097277770.png


■DATA
question_each warehouse.xlsx
I'm on the situation that can only use powerpivot by now,sorry for inconvinient...


that's all.Thank you for reading and your continuing support!

Best Regards,


2 REPLIES 2
ahadkarimi
Solution Specialist
Solution Specialist

Hi @ohnothimagain, give this a try, and if you encounter any issues, let me know.

test11 :=
VAR _sum =
    SUMMARIZE(
        'TEST_',
        'TEST_'[PN],
        "@Qty", SUM('TEST_[Qty]'),
        "@Req", SUM('TEST_[Req]')
    )
VAR _add =
    ADDCOLUMNS(
        _sum,
        "@diff", [@Qty] - [@Req]
    )
VAR _ftd =
    FILTER(
        _add,
        [@diff] > 0
    )
VAR _Trg =
    SELECTCOLUMNS(
        _ftd,
        "@PN", 'TEST_'[PN]
    )
VAR _result =
    CALCULATE(
        COUNTROWS('TEST_'),
        'TEST_'[PN] IN _Trg
    )

RETURN
    _result

Did I answer your question? If so, please mark my post as the solution! ✔️
Your Kudos are much appreciated! Proud to be a Solution Specialist!

Thank you for replying fast,I do appriciate!
but result was the same.. -1000's warehouse AAAA didn't appear.
(seemed to be still remained filter context to each row )

ohnothimagain_0-1727107342897.png

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.