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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

DAX SWITCH + SELECTEDVALUE()

Hello everyone! I'm struggling to solve a problem with a measure.

 

I'm using the wonderful resource of SWITCH + SELECTEDVALUE, but what happens when I need to perform a division, say, GMV/Orders. In the following case: ATV=GMV/Orders. 

 

VAR MySelection =
SELECTEDVALUE ('De-para'[Grouping])
VAR Mysubselection=SELECTEDVALUE(All_Data[KPI])
RETURN
SWITCH (
TRUE (),
MySelection="GMV",CALCULATE(sum(All_Data[Value]),All_Data[Grouping.1]="GMV")/1000000,
MySelection = "Orders",[Orders],
MySelection = "ATV",[ATV])
 
The disconnected table which contains the field Grouping.1 is the following:
 
KPI    Grouping.1
GMV            GMV
Orders         Orders
ATV              ATV
Discounts    DME
Mkt             DME
 
When I build the table I need, the KPI "ATV" shows the same data for every kpi, as if it wouldn't recognize the attribute as a table attribute. 
 
Any help? I need to solve this asap 😞
Thks in advance!
 
 
 
 
 
1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous ,

 

You need another Measure to calculate the value of GMV/Orders, then use it in current Measure .

ATV =
VAR GMV_ =
    CALCULATE ( [GMV], ALL ( All_Data ) )   //[GMV] is a measure that sum the value of GMV
VAR Orders_ =
    CALCULATE ( [Orders], ALL ( All_Data ) )   //[Orders] is a measure that sum the value of Orders
RETURN
    IF ( SELECTEDVALUE ( All_Data[Grouping.1] ) = "ATV", GMV_ / Orders_, BLANK () )

 

division =
VAR MySelection =
    SELECTEDVALUE ( 'De-para'[Grouping] )
RETURN
    SWITCH (
        TRUE (),
        MySelection = "GMV", [GMV] / 1000000,   //[GMV] is a measure that sum the value of GMV
        MySelection = "Orders", [Orders],   //[Orders] is a measure that sum the value of Orders
        MySelection = "ATV", [ATV]
    )

 

Then, the result should look like this.

vcazhengmsft_0-1647930763775.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

View solution in original post

2 REPLIES 2
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous ,

 

You need another Measure to calculate the value of GMV/Orders, then use it in current Measure .

ATV =
VAR GMV_ =
    CALCULATE ( [GMV], ALL ( All_Data ) )   //[GMV] is a measure that sum the value of GMV
VAR Orders_ =
    CALCULATE ( [Orders], ALL ( All_Data ) )   //[Orders] is a measure that sum the value of Orders
RETURN
    IF ( SELECTEDVALUE ( All_Data[Grouping.1] ) = "ATV", GMV_ / Orders_, BLANK () )

 

division =
VAR MySelection =
    SELECTEDVALUE ( 'De-para'[Grouping] )
RETURN
    SWITCH (
        TRUE (),
        MySelection = "GMV", [GMV] / 1000000,   //[GMV] is a measure that sum the value of GMV
        MySelection = "Orders", [Orders],   //[Orders] is a measure that sum the value of Orders
        MySelection = "ATV", [ATV]
    )

 

Then, the result should look like this.

vcazhengmsft_0-1647930763775.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

AlexisOlson
Super User
Super User

I don't quite understand the question. What are you expecting to happen when you "perform a division"? How is this division related to your switch measure?

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.