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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Sashwato
Helper II
Helper II

SelectedValue Measure DAX not working

Hello all,

 

I am currently stuck in getting this corrected and doesn't seem to work somehow. I have a slicer selection on the page - for STORE. I am trying to set condition based on different STORE selection from slicer. Below is the DAX measure I have created:

 

BrandName SelectedFormula =
var SelectedValue = SELECTEDVALUE(store[cdk_accounting_account])
RETURN
SWITCH(TRUE(),
SelectedValue = "PNH-A", (IF(inventoryvehicle_v[Brand Name] = "Porsche", inventoryvehicle_v[Brand Name], "Others")),
SelectedValue = "LH-A", (IF(inventoryvehicle_v[Brand Name] = "LAMB" || inventoryvehicle_v[Brand Name] = "LAM" || inventoryvehicle_v[Brand Name] = "MCLA" || inventoryvehicle_v[Brand Name] = "MCLRN", inventoryvehicle_v[Brand Name], "Others")))
 
The issue that I am running into is: If you look at both the IF statements, these are not aggregates which it is needed to run this logic. For us, it cannot be an aggregates since it is referring a scalar value comparison.
 
Below is the screenshot error I get:
 
Selectedvalue measure error.PNG
 
Can anyone suggest me a workaround to write this? Any help is appreciated!
 
Regards!
1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Sashwato ,

According to your description, I create a sample.

vkalyjmsft_1-1641808948484.pngvkalyjmsft_2-1641808969055.png

The two tables have relationship.

vkalyjmsft_3-1641809059636.png

Columns cannot be directly quoted in measure, as measure is aggregation operation, it can only refer to unique values, not a column. You can add MAX function to return the value of the current row, like this:

BrandName SelectedFormula = 
var SelectedValue = SELECTEDVALUE(store[cdk_accounting_account])
RETURN
SWITCH(TRUE(),
SelectedValue = "PNH-A", IF(MAX(inventoryvehicle_v[Brand Name]) = "Porsche", MAX(inventoryvehicle_v[Brand Name]), "Others"),
SelectedValue = "LH-A", IF(MAX(inventoryvehicle_v[Brand Name]) IN{ "LAMB" ,"LAM" ,"MCLA" ,"MCLRN"}, MAX(inventoryvehicle_v[Brand Name]), "Others"))

In this way, the measure works, but the brand name cann't be filtered by slicer.

vkalyjmsft_4-1641809158119.png

You can modify the formula like this:

BrandName SelectedFormula 2 =
VAR SelectedValue =
    SELECTEDVALUE ( store[cdk_accounting_account] )
RETURN
    SWITCH (
        TRUE (),
        SelectedValue = "PNH-A",
            IF (
                MAX ( 'inventoryvehicle_v'[account] ) = "PNH-A",
                IF (
                    MAX ( inventoryvehicle_v[Brand Name] ) = "Porsche",
                    MAX ( inventoryvehicle_v[Brand Name] ),
                    "Others"
                ),
                BLANK ()
            ),
        SelectedValue = "LH-A",
            IF (
                MAX ( 'inventoryvehicle_v'[account] ) = "LH-A",
                IF (
                    MAX ( inventoryvehicle_v[Brand Name] ) IN { "LAMB", "LAM", "MCLA", "MCLRN" },
                    MAX ( inventoryvehicle_v[Brand Name] ),
                    "Others"
                ),
                BLANK ()
            )
    )

Here's the result.

vkalyjmsft_5-1641809355596.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

 

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

5 REPLIES 5
v-yanjiang-msft
Community Support
Community Support

Hi @Sashwato ,

According to your description, I create a sample.

vkalyjmsft_1-1641808948484.pngvkalyjmsft_2-1641808969055.png

The two tables have relationship.

vkalyjmsft_3-1641809059636.png

Columns cannot be directly quoted in measure, as measure is aggregation operation, it can only refer to unique values, not a column. You can add MAX function to return the value of the current row, like this:

BrandName SelectedFormula = 
var SelectedValue = SELECTEDVALUE(store[cdk_accounting_account])
RETURN
SWITCH(TRUE(),
SelectedValue = "PNH-A", IF(MAX(inventoryvehicle_v[Brand Name]) = "Porsche", MAX(inventoryvehicle_v[Brand Name]), "Others"),
SelectedValue = "LH-A", IF(MAX(inventoryvehicle_v[Brand Name]) IN{ "LAMB" ,"LAM" ,"MCLA" ,"MCLRN"}, MAX(inventoryvehicle_v[Brand Name]), "Others"))

In this way, the measure works, but the brand name cann't be filtered by slicer.

vkalyjmsft_4-1641809158119.png

You can modify the formula like this:

BrandName SelectedFormula 2 =
VAR SelectedValue =
    SELECTEDVALUE ( store[cdk_accounting_account] )
RETURN
    SWITCH (
        TRUE (),
        SelectedValue = "PNH-A",
            IF (
                MAX ( 'inventoryvehicle_v'[account] ) = "PNH-A",
                IF (
                    MAX ( inventoryvehicle_v[Brand Name] ) = "Porsche",
                    MAX ( inventoryvehicle_v[Brand Name] ),
                    "Others"
                ),
                BLANK ()
            ),
        SelectedValue = "LH-A",
            IF (
                MAX ( 'inventoryvehicle_v'[account] ) = "LH-A",
                IF (
                    MAX ( inventoryvehicle_v[Brand Name] ) IN { "LAMB", "LAM", "MCLA", "MCLRN" },
                    MAX ( inventoryvehicle_v[Brand Name] ),
                    "Others"
                ),
                BLANK ()
            )
    )

Here's the result.

vkalyjmsft_5-1641809355596.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

 

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

 

Thank you for inputs and the example file! This resolved my issue.

amitchandak
Super User
Super User

@Sashwato , Are you trying to create a new column, That will not take the selected value.

 

If you are trying a new measure, then you need to take some aggregation on brand_name

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi Amit,

 

Yes that's an issue, I am trying to create a new measure. I am not sure what aggregation will come up here since it's a straighforward condition based on text.

 

Regards!

@Sashwato , You have use like example

 

Max(InventoryVehicleName[Brand]) = "Other"

 

and it will search for brand name in context.

 

Or write formula inside expression part of Sumx, maxx etc 

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 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.

Top Solution Authors