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
kompalli
Helper I
Helper I

Needed help with passing Variables

DAX USED: SWITCH(SELECTEDVALUE('View By'[Parameter Order]),
                0,RANKX(FILTER(ALLSELECTED(Product[company_name]),NOT(ISBLANK([Sales by Current Month]))),[Sales by Current Month)),
                1,RANKX(FILTER(ALLSELECTED(Product[BRAND_NAME]),NOT(ISBLANK([Sales by Current Month]))),[Sales by Current Month))

 

In the above mentioned scenerio we are trying to refer different columns(more than five) from same table. 
In that case, the query checks 5 times for the correct value and then gives the output.
so I tried creating a variable and pass it to the 5 columns as field parameter column and use SELECTEDVALUE to retrieve the selected value from the filter.

 

Unfortunately variables are not accepted in certain DAX Functions like SUM and ALLSELECTED.

 

Is there a workaround or a solution for the DAX to be more efficient and improve the performance.

1 REPLY 1
Anonymous
Not applicable

Hi @kompalli 

After I testing, the sum(), allselected() can support variables

e.g

Measure = SUMX(FILTER(ALLSELECTED('Table (2)'),[CUS]=MAX([CUS])),[value])

Measure 2 = SWITCH(SELECTEDVALUE(Parameter[Parameter Order]),0,RANKX(FILTER(ALLSELECTED('Table (2)'[CUS]),[Measure]>30),[Measure],,ASC,Dense),1,0)

Output:

vxinruzhumsft_0-1673332167708.png

 

Can you provide some detail error message or pbix file, I can offer more help.

 

Best Regards!

Yolo Zhu

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

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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