Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
test = IF( SELECTEDVALUE(PowerBiData[Afdeling];"PROD")="PROD";1 ) + IF( SELECTEDVALUE(PowerBiData[Afdeling];"MONT")="MONT";2 ) + IF( SELECTEDVALUE(PowerBiData[Afdeling];"ADM")="ADM";3 )
Hi,
I am trying to create a measure "test", which is to sum up/add each TRUE in a single value.
To elaborate, if statement 1 and 3 is found TRUE, then i would expect the value 4 (1+3=4).
I have a slicer, from where i select X different "Afdeling". So for each i select, my SELECTEDVALUE examines, whether each individual "Afdeling" is chosen, i.e. "PROD", "MONT", "ADM" and so on.
The thing is, the code works just fine if only one, none or all statements are true. But each time i choose between one and all, it will return the values as if in fact all statements were true.
Thanks in advance.
Solved! Go to Solution.
Hi @MSS
You may try below measure:
TestCalc = CALCULATE ( SUMX ( VALUES ( PowerBiData[Afdeling] ), SWITCH ( TRUE (), PowerBiData[Afdeling] = "ADM", 3, PowerBiData[Afdeling] = "Mont", 2, PowerBiData[Afdeling] = "Prod", 1 ) ) )
Regards,
Hi,
Try this and see if it gives the result you are after
TestCalc = CALCULATE(SUMX( Table; SWITCH ( TRUE (); Table[Column] = "ADM"; 1; Table[Column] = "Mont"; 2; Table[Column] = "Prod";3 ) ))
Just change the names of Table and column to your own
Hi,
Thanks for your answer,
Unfortunately, this returns the number of rows, which have "Afdeling" = the types selected on the slicer.
The 1, 2 and 3 are not really the end result im reaching for. I want to have an unique expression to be executed per TRUE if-statement. That is;
"Afdeling" = "PROD", then do x thing,
"Afdeling" = "ADM", then do y thing,
"Afdeling" = "MONT", then do z thing.
And again, the type of "Afdeling" is to be chosen on a Slicer within the report.
Hi @MSS
You may try below measure:
TestCalc = CALCULATE ( SUMX ( VALUES ( PowerBiData[Afdeling] ), SWITCH ( TRUE (), PowerBiData[Afdeling] = "ADM", 3, PowerBiData[Afdeling] = "Mont", 2, PowerBiData[Afdeling] = "Prod", 1 ) ) )
Regards,
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
User | Count |
---|---|
126 | |
78 | |
78 | |
59 | |
51 |
User | Count |
---|---|
165 | |
83 | |
68 | |
68 | |
59 |