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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Add two measures together that have slicers

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? 

 

Desired outcome: 
I would like to add these two measures together to get a final total. I'm using a yellow card right now as you can see on the screenshot below. It would be AMAZING if I could have this final total also being affected by the two slicers and read "Please Select User(s)", but that's just a nice cherry on top...

Measure 1 = 
FilterSelection.Oversight = IF(HASONEFILTER(elements[Oversight (Supervisor)]),elements[Oversight.Sum2],"Select a User")
 
Measure 2 = 
FilterSelection.Priority = IF(HASONEFILTER(elements[Assign To]),elements[Priority.Sum2],"Select a User")
 
Measure 3, (measure 1 + measure 2):
Measure.Priority.Oversight = [FilterSelection.Oversight] + [FilterSelection.Priority]


Screenshot #1: when slicers are not active
2021-01-25_13-57-29.jpg


Screenshot #2: when slicers are active

2021-01-25_13-29-53.jpg

1 ACCEPTED 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.

 

Sample .pbix has been update

 

Best Regards,
Liang
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

15 REPLIES 15
Anonymous
Not applicable

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...

V-lianl-msft
Community Support
Community Support

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)

Sample .pbix

 

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

Anonymous
Not applicable

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.

 

Sample .pbix has been update

 

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

Anonymous
Not applicable

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!!

Anonymous
Not applicable

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).

Anonymous
Not applicable

Wait, nevermind- I found it by going to the "Modeling" tab and clicking "New Table". Always new things to learn 😅

Anonymous
Not applicable

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? 

 

PBI_SuperUser_Rank@1x.png Proud to be a Super User.
If I helped, please accept the solution and give kudos
Linkedin

 

Anonymous
Not applicable

@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. 

Anonymous
Not applicable

@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.

 

PBI_SuperUser_Rank@1x.png Proud to be a Super User.
If I helped, please accept the solution and give kudos
Linkedin

 

Anonymous
Not applicable

Hey @lkalawski , Let me see if I can recreate it with test information... I'm using an API for the data currently.

Anonymous
Not applicable

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

 

lkalawski
Memorable Member
Memorable Member

@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]
)

 




PBI_SuperUser_Rank@1x.png Proud to be a Super User.
If I helped, please accept the solution and give kudos
LinkedIN

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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