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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
theotherside
Regular Visitor

DAX: calculate dynamic table/rows that update on user slicers

Hi community, this is my first post ever on the forum!

 

I have a transformed table named items (the data below is a mock up simplification to help with posting on a forum, but if I can solve the example below then I can probably solve my real problem)

 

transformed table: items

 

itemcolordirectionqty
aredin10
byellowin2
cblueout200
dyellowout40
eyellowout20
fredin35
gmulticolouredin1

 

I have lots of measures and visuals that help me slice and dice qty by the item, direction & color columns. That all works great. But I needs these visuals and/or measures to also pick up an additional two rows:

 

calculated table: items2

Itemcolordirectionqty
Xmulticolouredin= 2 * sum(items[qty]) where direction='in'
Ymulticolouredout= 2 * sum(items[qty]) where direction = out

 

The first three columns of items2 are hardcoded , the qty column needs to be calculated on the fly. the idea is that I can then create measures such as: combined_qty=items[qty] + items2[qty] (a mix of transfomreand still have the ability to slice and dice by color and direction

 

So why don't I just do this with power query, or a DAX calculated column? The reason is because I need the filters applied by the user (via slicers) on items to impact the calculation of items2[qty] on the fly. For example, if the user filters out red items, then the qty value for item X will be 6. (=3 * (2+1))

 

So why don't i just use measures, which automatically update on the fly with user interaction? The reason is because this returns a scalar value only, and not an entire row, but I need the visuals to be able to filter on items X and Y based on color and direction.

 

My last idea was a calculated table, but I got stuck trying to do that as it's a bit above my level of understanding. 

 

Is what I'm trying to achieve possible?

Thank you so much in advance!

1 ACCEPTED SOLUTION

Hi @theotherside ,

 

Please try:

 

QTY Measure = 
var _a = ALLSELECTED('Union Item'[color])
var _b = SUMX('Union Item',SWITCH([item],
"X",CALCULATE(2*SUM('Union Item'[qty]),FILTER(ALL('Union Item'),[direction]="in"&&[color] in _a)),
"Y",CALCULATE(2*SUM('Union Item'[qty]),FILTER(ALL('Union Item'),[direction]="out"&&[color] in _a)),
CALCULATE(SUM('Union Item'[qty]))))
return _b

 

Final output:

vjianbolimsft_0-1684204156696.png

Best Regards,

Jianbo 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

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @theotherside ,

 

The calculation table does not change according to your filtering, try using measure:

First union the two table:

vjianbolimsft_0-1683165930588.png

Then apply the measure to the table visual:

QTY Measure = 
var _a = ALLSELECTED('Union Item'[color])
var _b = 
SWITCH(SELECTEDVALUE('Union Item'[item]),
"X",CALCULATE(2*SUM('Union Item'[qty]),FILTER(ALL('Union Item'),[direction]="in"&&[color] in _a)),
"Y",CALCULATE(2*SUM('Union Item'[qty]),FILTER(ALL('Union Item'),[direction]="out"&&[color] in _a)),
SUM('Union Item'[qty]))
return _b

Final output:

vjianbolimsft_1-1683166788885.png

vjianbolimsft_2-1683166810588.png

Best Regards,

Jianbo Li

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

Hi @v-jianboli-msft

 

Thank you so much for your reply it has been incredibly helpful! I am sorry for the delay in my reply to you.

 

I have tried your solution. If I use your second screenshot as an example, the QTY Measure is correctly calculating which is great. However what I was hoping is that the total of QTY Measure, rather than being 246, would actually be 738. So in this way the user can filter by whatever columns they like, and not only will the QTY Measure of X and Y update dynamically, but any sum aggregation of QTY Measure will also update dynamically. Is this possible?

I know this is pointless for my colour/direction/qty example, but for my real world application this is crucial.

 

Thank you again!

Simon

Hi @theotherside ,

 

Please try:

 

QTY Measure = 
var _a = ALLSELECTED('Union Item'[color])
var _b = SUMX('Union Item',SWITCH([item],
"X",CALCULATE(2*SUM('Union Item'[qty]),FILTER(ALL('Union Item'),[direction]="in"&&[color] in _a)),
"Y",CALCULATE(2*SUM('Union Item'[qty]),FILTER(ALL('Union Item'),[direction]="out"&&[color] in _a)),
CALCULATE(SUM('Union Item'[qty]))))
return _b

 

Final output:

vjianbolimsft_0-1684204156696.png

Best Regards,

Jianbo Li

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

Thank you so much this work as expected! Thank you for your help!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.