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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
androo
Advocate II
Advocate II

Pivot (Matrix) and Visual based on two Bins/Bucket columns

I am working in Power BI and am trying to solve a problem and create a visualisation that is pretty trivial in Excel, but, I can't figure out how to do it in PBi. I've uploaded an XL file which shows what I want to do, but, in Power BI.

The data table in the my real problem is pulled in by Power Query, and Vals 1 and 2 are calculated columns in PBi based on other cols pulled in by PQ (not shown in my XL example, I don't think it matters that I'm not showing the cols that Val 1 and Val 2 are calculated from). Bins 1 and 2 in turn are columns created by PBi's "Data Groups" feature and based on the calculated columns Val 1 and Val 2.

The end result required is a table and a chart showing the count of values falling in Bins 1 and 2 against one another. Like the "Bins Table" and "Chart One" in my XL workbook. 

Of course my real problem has a lot more data, but, I think this captures what the problem is. I've tried a few things, but, for example, as you can only use one relationship between tables in PBi what I get using that approach is the result shown in chart 2 of the XL workbook. I thought of doing something analagous to the "Sumif" approach that works in Excel (albeit, an aside, that structured references don't seem to work in Excel with the sumif function), but, that would require two relationships between my "Bins Table" and my "Data table" and PBI won't allow that. Is there a way to do this with measures? With a "detached table". I'm stumped at the moment.

 

Here's a link to my XL workbook Chart from Two Bins

2 ACCEPTED SOLUTIONS

Hi @androo ,

 

Here I create a sample by data in Excel to have a test. 

Here I inactive both relationships from [Bin Tag] to [Bin1] and [Bin2].

RicoZhou_0-1653031810240.png

Measure:

Bin1 count = CALCULATE(DISTINCTCOUNT('Table'[ID]),USERELATIONSHIP('Table'[Bin1],Bin[Bin Tag]),'Table'[Bin1]<>BLANK())
Bin2 count = CALCULATE(DISTINCTCOUNT('Table'[ID]),USERELATIONSHIP('Table'[Bin2],Bin[Bin Tag]),'Table'[Bin2]<>BLANK())
Bin2 count based on Bin1 = CALCULATE([Bin1 count],'Table'[Bin2]<>BLANK())

Result is as below.

RicoZhou_1-1653031907028.png

 

Best Regards,
Rico Zhou

 

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

androo
Advocate II
Advocate II

hi Rico,

I thought the answer would be measures, and, thanks, yes it seems it is. A bit of a pain as it means I have to write two long measures creating the ten or so bins I need rather than using the PBi built in grouping directly, but, it works and means I can then use slicers from my category data with the visual and get sense. So, thanks. I've uploaded a version of my example file, in PBi fixed and with some superfluous elements removed so that the solution is as clear as possible.

View solution in original post

4 REPLIES 4
androo
Advocate II
Advocate II

Oh, I did come across a Row Level Security problem in the past where I wanted to use "userelationship" but, apparently, in that scenario you can't. So that somwhat put that option out of my mind. But, it seems that it is a way to have two relationships, I'm presuming that at least one of them has to marked as inactive (although both are here) at least for limited purposes, from one table to another, that becomes a use case for the "use relationship" function.

androo
Advocate II
Advocate II

hi Rico,

I thought the answer would be measures, and, thanks, yes it seems it is. A bit of a pain as it means I have to write two long measures creating the ten or so bins I need rather than using the PBi built in grouping directly, but, it works and means I can then use slicers from my category data with the visual and get sense. So, thanks. I've uploaded a version of my example file, in PBi fixed and with some superfluous elements removed so that the solution is as clear as possible.

androo
Advocate II
Advocate II

I have been able to partially solve my problem. I created a BINs table in Power BI and then added two columns each counting the occurences of the Bin ID fromthe Bin Table value in the Bin 1 and then Bin 2 column of the data  table.

 

Curr Bin Count = calculate(DISTINCTCOUNT(EST077_Full_List[Property Reference]),filter(EST077_Full_List,EST077_Full_List[Bins: Curr PW]=Bins[Bin]))

 

Prop Bin Count = calculate(DISTINCTCOUNT(EST077_Full_List[Property Reference]),filter(EST077_Full_List,EST077_Full_List[Bins: Proposed PW]=Bins[Bin]))

 

For the limited aim of creating the "BIN table" and the "chart one" this has worked. However, it isn't a great result as I can't put this on another visual and then slice and fillter by other criteria in my model, which is why I think there is probably a better approach using measures.

Hi @androo ,

 

Here I create a sample by data in Excel to have a test. 

Here I inactive both relationships from [Bin Tag] to [Bin1] and [Bin2].

RicoZhou_0-1653031810240.png

Measure:

Bin1 count = CALCULATE(DISTINCTCOUNT('Table'[ID]),USERELATIONSHIP('Table'[Bin1],Bin[Bin Tag]),'Table'[Bin1]<>BLANK())
Bin2 count = CALCULATE(DISTINCTCOUNT('Table'[ID]),USERELATIONSHIP('Table'[Bin2],Bin[Bin Tag]),'Table'[Bin2]<>BLANK())
Bin2 count based on Bin1 = CALCULATE([Bin1 count],'Table'[Bin2]<>BLANK())

Result is as below.

RicoZhou_1-1653031907028.png

 

Best Regards,
Rico Zhou

 

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

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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