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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
quijote
Regular Visitor

Comparing DAX Measure with SELECTEDVALUE()

Sorry, I am still quite new to PowerBI and DAX.

 

I have created two measures: 

 
1. Localism = SELECTEDVALUE('ISSUE'[RaisedBy], "None")
 
which returns the user-selected slicer value for [RaisedBy], or "None" if nothing is selected, and:
 
2. Other_Template = CALCULATE(COUNTROWS(ISSUE), ISSUE[RaisedBy] <> "FR", ISSUE[CountriesImpacted] = "Template")
 
which returns the number of rows in the ISSUE table if the columns [RaisedBy] and [CountriesImpacted] take on certain values.
 
 
The above works fine because I have hard-coded the country to "FR".
 
 
However, if I try to replace the hard-coded "FR" with "[Localism]", it does not work:
 
3. Other_Template = CALCULATE(COUNTROWS(ISSUE), ISSUE[RaisedBy] <> "[Localism]", ISSUE[CountriesImpacted] = "Template")
 
 
However, I can see the value of the measure [Localism] output in a visual as "FR".
 
I have also added 'debug' measures:
 
4. Is_Localism_Blank = ISBLANK([Localism])
 
 
which returns <False>
 
and
 
5. Len_Localism = LEN([Localism])
 

which returns <2>.

 

quijote_0-1750084455996.png

 

 

Q. Why does 'code snippet 3' fail while 'code snippet 2' works?

6 REPLIES 6
v-sdhruv
Community Support
Community Support

Hi @quijote ,

Thanks for the update!
To help investigate further, could you please share some sample data or a minimal reproducible example that demonstrates the issue? That would really help in identifying a suitable solution.
How to provide a sample data
How to upload in Community

Best Regards,
Shruti


v-sdhruv
Community Support
Community Support

Hi @quijote ,

Good that you were able to resolve your query.
Can you please mark the answer as solution, so that other users can also benefit from it.
Thanks @AlexisOlson  and @speedramps  for your detailed response to the query.
Please feel free to reach out in case of any questions.
Thank You

Actually, this is not resolved yet.

 

I have the same problem but am investigating a suitable solution.

 

Will post here if / when I find one.

speedramps
Community Champion
Community Champion

Hi quijote 


You have made a few common mistakes, which most of us make when we fisrt start with DAX.

 

1st mistake is  SELECTEDVALUE() is nothing to do with teh SILICER of Filter pane

 SELECTEDVALUE() retreives the nutual filtrer context in you visual table or graph

For example whilst drawing this visual, on the Feb row, SELECETDVALUE(Month) will be "Fen" 

 

MonthSales
Jan123
Feb456
Mar789

 

 

CALCULATE(
COUNTROWS(ISSUE),
ISSUE[RaisedBy] <> "[Localism]"
)

 

However, this will trigger an error because you cant have a measure inside a measure

CALCULATE(
COUNTROWS(ISSUE),
ISSUE[RaisedBy] <> [Localism]
)

 

You can use the FILTER commadn to create a tempoary table

Example =
VAR temptable = FILTER(yourtablename,yourtablename[RaisedBy] <> [Localism])

RETURN
CALCULATE(
COUNTROWS(ISSUE),
temptable
)

 

You can put the filter in the CALCULATE but I recommend using VAR because it is easier to learn and test

Example2 =
CALCULATE(
COUNTROWS(ISSUE),
FILTER(yourtablename,yourtablename[RaisedBy] <> [Localism])
)

You have made a few common mistakes, which most of us make when we fisrt start with DAX.

 

1st mistake is  SELECTEDVALUE() is nothing to do with teh SILICER of Filter pane

 SELECTEDVALUE() retreives the nutual filtrer context in you visual table or graph

For example whilst drawing this visual, on the Feb row, SELECETDVALUE(Month) will be "Fen" 

 

MonthSales
Jan123
Feb456
Mar789

 

 

 

CALCULATE(
COUNTROWS(ISSUE),
ISSUE[RaisedBy] <> "[Localism]"
)

 

 

However, this will trigger an error because you cant have a measure inside a measure

 

CALCULATE(
COUNTROWS(ISSUE),
ISSUE[RaisedBy] <> [Localism]
)

 

 

You can add lots of conditions in FILTER
for example all big green issue

 

Example3 =
VAR temptable = 
FILTER(yourtablename,
  yourtablename[Size] = "Big" &&
  yourtablename[Colout] = "Green"
)

RETURN
CALCULATE(
COUNTROWS(ISSUE),
temptable
)

 

 

 

 

Learn more here
https://www.youtube.com/watch?v=xV-KwuSDFMQ

https://www.youtube.com/watch?app=desktop&v=FI1_N-imBxI&t=05m33s

 

I want to help you but your description is too vague. I suggest you close this ticker and start a new one from fresh.


You will get a quicker and better response without misunderstandings if you put time and effort into carefully writing a clear problem description with example input and output data. Look forward to helping you when this information is forthcoming


* Please DON'T copy & paste your DAX that does not work and expect us to fathom what you want. (That is just crazy). ‌‌
* Please DO give a simple non-technical functional description of what you want
* Keep it simple and break large projects into smaller questions and ask just one question per ticket.
* Rename columns to user friendly names. Avoid your own system jargon that we may not understand.
* Most importantly please provide example input data as table text (not a screen print) so helpers can import the data to build a solution for you. (Learn how to share data below)
* Provide the example desired output, with a clear step-by-step description of calculations and the process flow.
* Take time and care to use the same table and field names in the input, output and description so we can understand your problem and help you.
* Remove any unneeded tables, rows or columns which may cause confusion. Keep it short and concise with the minimal information regarding the key problem.
* Remember not to share private data ... we don't want you to get into trouble. ‌‌
* Please click the thumbs up button for these helpful hints and tips. Thank you.


Learn how to attach data in the forum using OneDrive:-
* Save your file in a OneDrive folder
* Right click on the file and click the “Share” blue cloud icon
* Click the bottom “Copy” button
* Click” Anyone with link can edit”
* Click “Can Edit”
* Click “Can View”
* Click “Apply” button
* Click “Copy”
* Paste the generated link via the forum, email, chat, or any other method.
* Helpers can then download your data, build a solution and share it back.


Learn how to attach data in the forum using Dropbox:-
1. Open Dropbox: Access the Dropbox folder on your computer or through the Dropbox web interface.
2. Select File/Folder: Find the file or folder you want to share.
3. Click Share (or Get Link): Look for a "Share" option or a similar "Get Link" option.
4. Choose Permissions: Decide whether to allow "view only" or "view and download" access.
5. Copy and Share: Copy the generated link and share it with anyone via the forum, email, chat, or any other method.

 

 

quijote
Regular Visitor

Thanks for looking into this.

 

I think I just fixed it with the following tweak:

 

Other_Template = CALCULATE(COUNTROWS(ISSUE), ISSUE[RaisedBy] <> SELECTEDVALUE('ISSUE'[RaisedBy], "None"), ISSUE[CountriesImpacted] = "Template")
 
Although your solutions looks more elegant, to be sure...
AlexisOlson
Super User
Super User

I'm pretty sure you aren't actually intending to check if ISSUE[RaisedBy] is the literal string "[Localism]".

 

Try using a variable (without quotes):

Other_Template =
VAR _Loc = [Localism]
RETURN
    CALCULATE (
        COUNTROWS ( ISSUE ),
        ISSUE[RaisedBy] <> _Loc,
        ISSUE[CountriesImpacted] = "Template"
    )

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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