Forum Discussion
DAX: Selectedvalue in IF doesn't work
- 8 years ago
Alright then!
Then i have some things that I would like you to check:
* Do a new measure, Measure = SELECTEDVALUE(Workers[Name])
* Place this measure next to the name column and compare the values. If they are not the same something is off.
* Also check the format of the name column.
I tried to recreate your problem but mine seems to work...
hours/month = IF(SELECTEDVALUE(Table1[Person])="TestP"; SUMX(Table1;Table1[9workinghours]*Table1[9hrmonthdays]); SUMX(Table1;Table1[8workinghours]*Table1[8hrmonthdays]) )
Selectedvalue(Column, alternative) works like this:
The function looks into a specific column and if there is only one value in that column it returns that specific value.
If there are more than one value in your column Selectedvalue will return the specified alternative or blank() if you did not specify an alternative.
Due to the fact that your first if statement "Selectedvalue(table[column]) = blank()" returns true - this makes me think that there is currently more values that only test persoon in that column.
Place a slicer and filter on test persoon to make sure that there is only one distinct value in that column.
Im sorry that this might be messy, but im quitting work now so im a little stressed with the typing.
Br,
J
Hi tex628 ,
Thanks for your reply. Hope you had a good weekend.
I know what you mean but it doesn't seem to work. Look at my example below, where my DAX is:
Case 1:
Werkuren per maand =
IF (
SELECTEDVALUE ( Workers[Name] ) = "Test Persoon";
CALCULATE ( SUM ( 'Calendar'[Werkdagen 4 dagen] ) ) * [Werkuren 9];
CALCULATE ( SUM ( 'Calendar'[IsWorkDay 5 dagen] ) ) * [Werkuren 8]
)
Case 2:
Werkuren per maand =
IF (
SELECTEDVALUE ( Workers[Name] ) = "Test Werknemer";
CALCULATE ( SUM ( 'Calendar'[Werkdagen 4 dagen] ) ) * [Werkuren 9];
CALCULATE ( SUM ( 'Calendar'[IsWorkDay 5 dagen] ) ) * [Werkuren 8]
)
It seems to effect the totals, but the values for each month don't change. So: the total is right (the 'true' in my statement), the values each month are wrong (the 'false' in my statement).
I can't find the right way to do this.
- tex6288 years agoCommunity Champion
Alright then!
Then i have some things that I would like you to check:
* Do a new measure, Measure = SELECTEDVALUE(Workers[Name])
* Place this measure next to the name column and compare the values. If they are not the same something is off.
* Also check the format of the name column.
I tried to recreate your problem but mine seems to work...
hours/month = IF(SELECTEDVALUE(Table1[Person])="TestP"; SUMX(Table1;Table1[9workinghours]*Table1[9hrmonthdays]); SUMX(Table1;Table1[8workinghours]*Table1[8hrmonthdays]) )- RemiAnthonise8 years agoHelper V
tex628 , thanks a lot. You made my day! I don't know exactly how but it works and that's fine to me.