Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hello there!
I'm a semi-new PowerBi user, and I can't figure out how to add two measures together that are both affected by a slicer. I've tried everything I can think of, and I can never get it to add up properly, any thoughts?
Screenshot #1: when slicers are not active
Screenshot #2: when slicers are active
Solved! Go to Solution.
Hi @Anonymous ,
SELECTEDVALUE() function only supports single selection. If you want to select more than one, you need to create disconnected tables as slicers. Then use VALUES() function instead of SELECTEDVALUE() function. And create a condition measure and put it into the corresponding visual level filter.
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @V-lianl-msft,
Another question for you if you wouldn't mind, where in the new code that you sent would I be able to put something like "SUMX(DISTINCT...)"? Trying to dissect the code now to see where it fits...
The calculations are off because each ID could have multiple rows to it in the original table. So when I have "if this task's priority is normal, it equals 10", it could actually give me a total of 20 or 30 if that ID has multiple rows to it...
Hi @Anonymous ,
Based on your description, I recreated measure.
Both slicers are from the same table, you need to clear the filters in the table.
Total.Num.Of.Open.Tasks =
var select_ = SELECTEDVALUE(SampleData[Oversight (Supervisor)])
return CALCULATE(distinctCOUNT(SampleData[id]),FILTER(ALL(SampleData),SampleData[Oversight (Supervisor)]=select_))
Priority.Sum2 =
var select_= SELECTEDVALUE(SampleData[Assign To])
return CALCULATE(SUM(SampleData[Priority.Value]),FILTER(ALL(SampleData),SampleData[Assign To]=select_))
Oversight.Sum2 =
var num_ = [Total.Num.Of.Open.Tasks]
var select_ =SELECTEDVALUE(SampleData[Oversight (Supervisor)])
return (num_ * 10)-
CALCULATE(COUNTROWS(FILTER(ALL(SampleData),SampleData[Status] = "On hold"&&SampleData[Oversight (Supervisor)]=select_))*10)
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @V-lianl-msft , Oh nice! That's awesome! That's closer than I would have ever gotten it.
It seems to break when I click users 2-5 in the top slicer. The numbers work well when using the bottom slicer, but the top one seems to be inconsistent. Any thoughts? Is that happening on your end as well?
Hi @Anonymous ,
SELECTEDVALUE() function only supports single selection. If you want to select more than one, you need to create disconnected tables as slicers. Then use VALUES() function instead of SELECTEDVALUE() function. And create a condition measure and put it into the corresponding visual level filter.
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @V-lianl-msft ,
Oh, that's good to know! That's awesome! Thanks so much for all your help- it works for me now!!
Hi @V-lianl-msft ,
Quick question for you: How did you create those new tables in the example you sent?
I'm trying to create my own by clicking "EnterData", but the tables created don't have the same icon as yours do (calendar + calculator icon).
Wait, nevermind- I found it by going to the "Modeling" tab and clicking "New Table". Always new things to learn 😅
Hi @lkalawski , Thanks for helping me out! The card still isn't giving me the right value unfortunately after trying the two solutions you shared. Is there another visual I should be using for this? I'm also open to doing this in other ways if you know a better way to go about this whole thing.
Side note, thanks for showing how to have it say "select users", that's awesome!!
@Anonymous
Can you share the error that you received?
Proud to be a Super User. If I helped, please accept the solution and give kudos! |
@lkalawski , Unfortunately, there's no error message- it shows correctly the "Select Users" string from your code, and when I click something in both slicers it shows a number. It's just not showing the right number. From the screenshots, it should be just adding the two measures you see together (190+210=400). But it isn't giving me the correct total.
It will change when I select different users, but again, not giving me the right totals based on the selections.
@lkalawski , I even tried using variables to do all the calculations in one measure, and it's still not showing the right numbers when a user is selected.
Measure.Priority.Oversight =
var testOversight =
IF(HASONEFILTER(elements[Oversight (Supervisor)]),
(([Total Number of Open Tasks] * 10)-(CALCULATE(COUNTROWS(elements),elements[Status] = "On hold")*10))
,0)
var testPriority =
IF(HASONEFILTER(elements[Assign To]),
(SUM(elements[Priority.Value]))
,0)
RETURN
IF(HASONEFILTER(elements[Assign To]) &&
HASONEFILTER(elements[Oversight (Supervisor)]),
testOversight + testPriority,
"Select Users")
However, the numbers, even though they're wrong, are consistent. For example:
- clicking User#1 in both slicers = 50
- clicking User#2 in both slicers = 100...
Any thoughts?
Hi @Anonymous
Can you share your .pbix file with your structure and without sensitive data? It will help to find the issue, because at this moment I don't know your structure of data.
Proud to be a Super User. If I helped, please accept the solution and give kudos! |
Hey @lkalawski , Let me see if I can recreate it with test information... I'm using an API for the data currently.
Hey @lkalawski , here you go! The idea of the file is to have a way to show our boss which team members have too much or too little on their plates.
https://drive.google.com/file/d/1p-asGNSTwXRbC2Gh8DIF6Rq2neNHkv6v/view?usp=sharing
@Anonymous
I see two solutions at this moment:
1. Use the same way like in the Measure 1 and 2:
Measure.Priority.Oversight =
IF (
HASONEFILTER ( elements[Assign To] )
&& HASONEFILTER ( elements[Oversight (Supervisor)] ),
[FilterSelection.Oversight] + [FilterSelection.Priority],
"Select Users"
)
2. Or you can check the result of measures 1 and 2 and display correct information in the yellow card:
Measure.Priority.Oversight =
IF (
[FilterSelection.Oversight] = "Select a User"
|| [FilterSelection.Priority] = "Select a User",
"Select Users",
[FilterSelection.Oversight] + [FilterSelection.Priority]
)
Proud to be a Super User. If I helped, please accept the solution and give kudos! |
User | Count |
---|---|
128 | |
108 | |
99 | |
65 | |
62 |
User | Count |
---|---|
137 | |
115 | |
102 | |
71 | |
61 |