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

Filter a table with the StDev of a UNIONed column within a Var Table

I am trying to find the StDev of values for a filter, but I need to merge the data from two columns in my table first.
This is what I have tried, but I cannot figure out how to merge columns in a Variable, and then reference one of those columns in a filter,I know other ways to do it, I am just trying to figure it out in a DAX formula for my own satisfaction at this point.  Any help would be appreciated!

AllCitys =    
VAR   VARTable = FILTER(
UNION(
SELECTCOLUMNS(ShipmentInfo,"City",ShipmentInfo[City 1],"State",ShipmentInfo[State 1],"Number",ShipmentInfo[Number 1]),
SELECTCOLUMNS(ShipmentInfo,"City",ShipmentInfo[City 2],"State",ShipmentInfo[State 2],"Number",ShipmentInfo[Number 2]))
,[Number] <> 9999 && [Number] >=0)

 
RETURN
UNION(
SELECTCOLUMNS(ShipmentInfo,"City",ShipmentInfo[City 1],"State",ShipmentInfo[State 1],"Number",ShipmentInfo[Number 1]),
SELECTCOLUMNS(ShipmentInfo,"City",ShipmentInfo[City 2],"State",ShipmentInfo[State 2],"Number",ShipmentInfo[Number 2]))
, [Number] <= STDEV.P([VARTABLE[Number] *3)


 


ShipmentInfo Table:
City 1State 1Number 1City 2State 2Number 2
NewYorkNY1BostonMA4
MinneapolisMN7ChicagoIL17
BostonMA5NewYorkNY6
ChicagoIL12MinneapolisMN60


New Table: 

CityStateNumber
NewYorkNY1
MinneapolisMN7
BostonMA5
ChicagoIL12
BostonMA4
ChicagoIL17
NewYorkNY6





1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

" RETURN
UNION"

 

You are missing the second Filter.  But even then you can only return this into a calculated table.  A measure can only be a scalar value.

 

Here is the DAX that results in a calculated table:

 

AllCitys = 
VAR   VARTable = FILTER(
UNION(
SELECTCOLUMNS(ShipmentInfo,"Number",ShipmentInfo[Number 1]),
SELECTCOLUMNS(ShipmentInfo,"Number",ShipmentInfo[Number 2]))
,[Number] <> 9999 && [Number] >=0 )

RETURN
FILTER(UNION(
SELECTCOLUMNS(ShipmentInfo,"City",ShipmentInfo[City 1],"State",ShipmentInfo[State 1],"Number",ShipmentInfo[Number 1]),
SELECTCOLUMNS(ShipmentInfo,"City",ShipmentInfo[City 2],"State",ShipmentInfo[State 2],"Number",ShipmentInfo[Number 2]))
, [Number] <= STDEVX.P(VARTable,[Number]))

View solution in original post

2 REPLIES 2
lundande
Frequent Visitor

Thank you!

lbendlin
Super User
Super User

" RETURN
UNION"

 

You are missing the second Filter.  But even then you can only return this into a calculated table.  A measure can only be a scalar value.

 

Here is the DAX that results in a calculated table:

 

AllCitys = 
VAR   VARTable = FILTER(
UNION(
SELECTCOLUMNS(ShipmentInfo,"Number",ShipmentInfo[Number 1]),
SELECTCOLUMNS(ShipmentInfo,"Number",ShipmentInfo[Number 2]))
,[Number] <> 9999 && [Number] >=0 )

RETURN
FILTER(UNION(
SELECTCOLUMNS(ShipmentInfo,"City",ShipmentInfo[City 1],"State",ShipmentInfo[State 1],"Number",ShipmentInfo[Number 1]),
SELECTCOLUMNS(ShipmentInfo,"City",ShipmentInfo[City 2],"State",ShipmentInfo[State 2],"Number",ShipmentInfo[Number 2]))
, [Number] <= STDEVX.P(VARTable,[Number]))

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.